I'm using GNUPlot.Simple for Haskell and am trying to change the colour of my plots.
Specifically when I use the code:
plotListsStyle [][ ((PlotStyle {plotType = Lines, lineSpec = CustomStyle [ PointSize 0.1, LineTitle "First "] }) , ( zip [0..10] [0..10]))]
I want to change the colour of the plot.
I tried looking at the source code here https://www.stackage.org/haddock/nightly-2022-01-23/gnuplot-0.5.6.1/Graphics-Gnuplot-Simple.html, but couldn't figure out if there is anyway to do this.
Does anyone know how to do this or can recommend an alternative?
Thanks
From a quick look at the summary page in your link, it seems that the Simple variant of the Haskell wrapper does not provide a means to access the "linecolor" attribute of lines, points, etc. So you get only the default colors.
On the other hand, if the script it produces is fed to a standard build of gnuplot then the program will on entry read a system- and/or user- initialization script. So you could change the default line colors in that initialization script and the change would affect subsequent execution of scripts produced by your Haskell wrapper.
For example, if you want the color of the first plot to be green and the second plot cyan, you could place the lines
set linetype 1 linecolor "forest-green"
set linetype 2 linecolor "cyan"
in the file ~/.gnuplot. That would replace the first two colors of the default sequence.
I have 3000 .dat files which I want to plot using gnuplot.
They are all named as "iteration_1", ...", iteration_93", ..."iteration_1247",... (not in the format "iteration_XXXX", if this information is helpful).
Each of those files is to be plotted in an .eps file - my final intention is to do a video (an evolution of those plots), which I can easily make if I have the .eps files.
Is there any way to quickly command gnuplot to do this? All the questions I have found remotely similar to my situation were all actually regarding putting data from different files into one plot in a single file.
Again, I do not want to put all the plots into a single .eps file. I want 3000 .eps files.
Thanks in advance!
Simply put your plotting routine in a do for loop. By the way, gnuplot can also do animated GIFs. Check help gif.
### create output files in a loop
reset session
set terminal epscairo
do for [i=1:3000] {
FILE = sprintf("iteration_%d",i)
set output FILE.".eps"
plot FILE.".dat" u 1:2 w l # or change your extension and plot command accordingly
}
set output
### end of code
I'm trying to plot data from two different rosbag files using gnuplot. I'm trying to automate this as I have quite a few files that will need to be run.
I need to take the first element of the first column of each file and offset the data of the column w.r.t. that (and then divide by 10^9) to get the time in seconds. My issue is my script returns something different when I run it multiple times. It will either return the first, the second, or (occasionally) the third plot command, which is what I'm interested in.
The code I've cobbled together is below:
#!/bin/bash
gnuplot -persist <<-EOFMarker
set autoscale
set datafile separator ","
set key autotitle columnhead
plot "bag1" using (\$1):2 with linespoints
first=GPVAL_DATA_X_MIN
plot "bag2" using (\$1):3 with linespoints
second=GPVAL_DATA_X_MIN
plot "bag1" using ((\$1-first)/10**9):2, "bag2" using ((\$1-second)/10**9):3
EOFMarker
An example of the dataset is:
%time,field.1,field.2,field.3
1.50317427276591E+018,23,64,64
1.50317427281556E+018,232,74,64
1.50317427285689E+018,216,76,64
1.50317427287325E+018,183,85,64
1.50317427292519E+018,165,89,64
1.50317427298662E+018,129,96,64
1.50317427300161E+018,115,101,64
1.50317427309547E+018,102,112,64
And the second input file is:
%time,field.1,field.2,field.3,field.4
1.50317425501603E+018,55,45,229,98755
1.50317425501843E+018,55,45,229,98752
1.5031742550235E+018,51,43,229,98758
1.50317425502979E+018,51,43,229,98761
1.50317425504176E+018,55,41,231,98764
1.50317425504579E+018,55,41,231,98770
1.50317425504728E+018,50,42,232,98773
1.50317425504855E+018,50,42,232,98773
1.50317425505353E+018,55,41,229,98770
1.50317425506442E+018,55,41,229,98770
I've never experienced code where multiple runs produces different results. Can anyone point me in the right direction to fix this mess?
The outputs are the three plots below. No error message is output from the script at any time.
First output:
Third (and desired) output:
I don't know why you are sometimes getting different results; I always get the output of the last plot command. However, you seem to be using the first two plot commands only to get the minimum value of the first column for each of the two files. A better way that doesn't generate any plots would be
set datafile separator ","
set key autotitle columnhead
stats "bag1" using 1
first=STATS_min
stats "bag2" using 1
second=STATS_min
plot "bag1" using (($1-first)/10**9):2, "bag2" using (($1-second)/10**9):3
I can connect the dots of a data file by including with lines in the plot command. Is there a way to set this fixed (I was hoping for set with lines) so I don't have to explicitly include it in every call of plot?
Use
set style data line
to achieve this. Similar options are also available for functions
set style function boxes
I have some C++ code that generates data I want to create an animated gif (or equivalent) from. The data is output into .txt files with the names 1, 2, 3, 4 ..., N with 2 columns (x y data points). For simplicity say we use 100 files.
There seems to be 1 of 2 ways to do this, either create 100 png images from the 100 files then use GIMP to create a gif or create a gif automatically via GNUplot. The first I should be able to do with a loop, say;
set term png
for [i=1:100] {set output "data".i."png"; plot 'filepath/'.i.'.txt' with lines title ""; set output}
Which gives me the error: 'invalid complex constant'. This I suspect is just be being bad with GNUplot syntax.
As for the second, the examples I can find make it unclear how to use data to generate the plots.
Any help is much appreciated.
For gnuplot versions older than 4.6 you can use reread to do such kind of looping.
Consider the file looper.gp:
set output 'data'.i.'.png'
plot 'filepath/'.i.'.txt' with lines notitle
i = i + 1
if (i <= 100) reread
Call this with
i = 1
set terminal png
load 'looper.gp'
set output