Is there anyway to change colour of plots in Haskell GNUPlot.Simple package - haskell

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.

Related

How to specify color of multiplot title

This might be a silly question, but I can't figure out how to specify the (font-) color for the title in a multiplot.
gnuplot> set multiplot layout 2,1 title "Title" font ",14" tc rgb "blue"
^
invalid or duplicate option
This feature does not seem to be supported currently "out of the box".
However, it looks like that the reason is just because the color specification is not parsed. To be more specific, the function multiplot_start in src/multiplot.c parses only font name,size so the remaining tokens in your example cause the invalid or duplicate option error.
A bit dirty solution would be to add this feature manually. It seems that to this end, one needs to do the following:
add #include "misc.h" at line 50 of src/multiplot.c
at line 255 of the same file, add
-
if (equals(c_token,"tc") || almost_equals(c_token,"text$color")) {
parse_colorspec(&(mp_layout.title.textcolor), TC_VARIABLE);
continue;
}
Then after running the standard ./configure ... && make install commands, your example produces in this customized version of Gnuplot the desired blue title...

gnuplot - multiple plot files using the same style settings, but different number of plot lines?

This is my problem: I have 4 different data files; and I need to create various plots on png, using data in these files.
I would like to have all in a function that I call in a script, so I would like to put together as many common statement as I can.
The plot have different file names, but they use mostly the same settings: the legend position, the title, the axis label, the range, border line style.
What change is the data, coming from different data files, the number of lines on the same plot (some has for example 1 set of data, others has 4-5 per plot), and the color to differentiate them.
Is there a clean way to group what is similar, so I don't end up writing the same things for each of my plot? I've check the doc and I was not able to find a solution to this; since the style is set for each dataset, so I can't really do anything to group it.
Found some questions here that look similar, but the problem is totally different...I don't need to merge data from different dataset, but I need to create different plot files, which only share most of the common settings. To make a generic example, I need a way to do something like a CSS style file, so the style stay the same, but the content of the plot (and the name of the file) changes.
I am using shell script for the code; so I wrapped a gnuplot command in a shell function.
Thanks
You can put all common settings in one file (lets say settings.gp) and load them from your main files with load 'settings.gp'. That works as if you would write the actual commands in place of the load command. Therefore you can define some variables before loading the settings file to change the behavior.
File settings.gp:
set terminal pngcairo
set output outfile
set style increment user
if (plotNum == 2) {
set style line 1 lt 5
set style line 2 lt 6
} else {
set for [i=1:5] style line i lt i+2
}
(Note, that this kind of if statement requires gnuplot version 4.6 and newer).
File main.gp
outfile = 'first.png'
plotNum = 2
load 'settings.gp'
plot x, x**2
The command set style increment user automatically iterates over line styles instead of line types in the plot command.
That is of course only an example, basically you can include any kind of tests and conditions in you settings.gp. An other possiblity is using the call command.

Improving gnuplot 3d plots from data files with pm3d

I'm trying to graph an approximate solution (finite element method) to the Navier-Stokes equation. I've got a file called plotNSu1 that looks like this:
6 1 4.21022e-34
5.95 1 8.15227e-34
5.9693 0.970854 0.055197
6 1 4.21022e-34
5.9693 0.970854 0.055197
6 0.95 0.0941333
6 1 4.21022e-34
5.9693 0.970854 0.055197
5.92625 0.951192 0.0915468
5.9693 0.970854 0.055197
5.95 1 8.15227e-34
5.92625 0.951192 0.0915468
...
(The entries are x y z, grouped so that there's a blank line between each set of 4 points).
I use the following command to plot:
splot "plotNSu1" with lines
Butt I would like to make it look nicer, easier to read. (There's a small dip at one spot that's difficult to see, but is an important part of the solution).
I've found lots of examples using pm3d interpolate, but none seem to work for me. I've tried set style pm3d, and other set style commands, I've tried set pm3d map interpolate 10,10, and splot "plotNSu1" with pm3d, as well as so many other similar things stolen from the examples I've found that I can't keep track. Most of the time I just get an empty window with the color key and no plot, and often it sends me an empty 2d window.
I would like to have the color change with the contour of the plot, to make the little dip easier to see. Does anyone know how to do this? Here's one of the websites I've been trying to use, to see what I'm aiming for: http://gnuplot.sourceforge.net/demo/pm3d.html
I tried to post the image, but as I do not have enough reputation, I can't. But it's difficult to see what's going on because the graph is just all red.
I found a way to make this work, more or less, thanks to #Christoph's help and this other question suggested by stackoverflow: gnuplot pm3d plot triangle data
With my data in the file described above, in gnuplot I type:
set dgrid3d
set pm3d corners2color c2
splot "plotNSu1" using 1:2:3 with pm3d
The result isn't perfect, it looks a little choppy, but it basically does what I wanted, I can see the "dip" in my graph much better now.

Gnuplot: line opacity / transparency?

I am using Gnuplot to successfully plot some time series data. However, the series are fairly dense (10,000's of samples in about 5 inches of space), and when I plot multiple series, it is hard to see underneath the series that was plotted on top. Is there any way to make the lines have a bit of opacity or transparency (i.e. make the line transparent so underneath lines are visible)?
Excel has this capability, but I would much prefer to use Gnuplot.
Below is a sample of what I'm talking about. You can't see the red lines under the green lines. I would actually like to add a third time series. I am plotting with the command:
plot [][-3:3] 'samples_all.csv' using 1:7 title 'horizontal' w l ls 1, '' using 1:8 title 'vertical' w l ls 2"
Good news! This has been implemented in gnuplot. Example syntax is
plot x lw 10, -x lw 10 lc rgb "#77000000"
This will plot x as a red line and -x as a transparent black line (it looks gray). The first pair of two characters in the rgb specification define the alpha (transparency) channel ("#AARRGGBB"). The normal syntax ("#RRGGBB") still works.
old (gnuplot < 5.0 or so) answer for reference:
If you want to make lines plotted for time series data, the answer is no (see discussion here). You can't set a line style to be transparent. Transparency only works for filling under curves, and it has to be printed to the right terminal type.
I ran into this problem myself recently, I hope this feature will be added in a future version of gnuplot.
This may be what you're looking for.

Is it possible to set the "linetype" in gnuplot while using "linecolor variable"?

I have a tab-separated data file containing a number of (double-blank-line-separated) datasets and I want to plot a line for each of them. I want to be able to set the linetype (by this I'm referring to solid/dashed/dotted). I want each line to be a different color.
I can plot them all different colors using this:
plot 'example.dat' using 1:2:(column(-2)) with lines linecolor variable
And I can set the linetype but plot them all the same color using this:
plot 'example.dat' using 1:2:(column(-2)) with lines linetype 5
But when I combine them, the linetype is not what I set it to (in this case I just get a solid line).
plot 'example.dat' using 1:2:(column(-2)) with lines \
linetype 5 linecolor variable
Is there a way to achieve this?
I'm using gnuplot 4.6, tried with the x11 and postscript terminals.
This looks like a bug to me. Unfortunately, I don't think too many gnuplot devs hang out on StackOverflow, so we might not ever find out. (I would encourage you to submit a bug report though and keep me updated on any progress that might be made)...
If you're really using column(-2) to pick out the colors, the problem becomes a lot easier and you should be able to do that using plot iteration (as long as you know an upper limit on the number of datasets).
NDSET=3 #This will issue a warning if NDSET is too big, but will still work.
plot for [IDX=0:NDSET] 'example.dat' index IDX using 1:2 with lines linetype 5 linecolor IDX+1
The indexing starts from 0 and corresponds to column(-2). Linecolor 0 isn't defined (I don't know why gnuplot uses two different conventions here -- I suppose because in theory the colors corresponding to any particular linestyle are terminal dependent, so it doesn't really matter too much anyway...)

Resources