1

Here is the problem I am having with GNUPLOT: I have data files with two columns each (one for the voltage the other for the current) and each obtained for a certain temperature (which is specified in their name something like iv_300K.dat, iv_290K.dat etc.).

Now what I want is to plot each data file on the same graph and each plot to have a colour based on the file name (I would like to show you a figure I made with Mathematica but it seems that my reputation is too low...)

So lets say I have iv_300K.dat, iv_250K.dat and iv_160K.dat I would like to have three curves coloured first red, second green-ish and third blue, but based on the temperature information in the file name.

I am thinking something similar to what I did in Mathematica:

ColorData["DarkRainbow"][Rescale[T, {160, 350}]]

Where "DarkRainbow" is a colormap and Rescale[x,{min,max}] gives x rescaled to run from 0 to 1 over the range min to max (according the Mathematica documentation).

So Rescale[250,{160,350}] = 0.473684

At the moment in GNUPLOT I am using the following for testing purposes:

plot for [i=350:160:-10] 'iv_'.i.'.K.dat' using 1:2 with lines title sprintf("".i." K")

but I can't get the colours to map the temperature.

Any help is appreciated!

1 Answer 1

1

Use linecolor palette frac to select a color from a palette based on an value in the range [0:1]:

set cbrange [160:350]
set style data lines
plot for [i=350:160:-10] 'iv_'.i.'.K.dat' using 1:2 linecolor palette frac (i-160.0)/(350.0-160.0) title sprintf("%dK", i)
Sign up to request clarification or add additional context in comments.

9 Comments

Thank you for your suggestion. I have just tried it but unfortunately I am getting the following error: Not enough columns for variable color. I have no idea where this is coming from.
I got it! it should be frac instead of frace! It works! Sweet! Now I don't mean to seem ungrateful but how can I change the color scheme to go from blue to red?
Got this as well! I found this resource here: github.com/Gnuplotting/gnuplot-palettes and I copy and pasted the description of the palette I wanted (jet in this case) at the beginning of my script and it works!
I have one more question: how can I add the unit next to the numbers in the legend on the right? I want to have it displayed something like 340 K, 250 K etc
That is already contained in my answer: title sprintf("%d K", i)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.