I used to make nice pm3d maps with gnuplot with a simple code like this:
set pm3d map
set palette
splot data using 1:2:3
But that had data organized as follows:
1 1 1
1 2 1
1 3 2
2 1 1
2 2 3
2 3 4
3 1 1
3 2 1
3 3 3
I never really understood the need for line break here but it worked. Now my data is quite different, the data in the first and second columns are not as simply repeated they are like this:
1.1 -1 2
1.2 3 3
1.11 4 4
...
I don't have any line breaks there since i have not idea how i should organise them. The question is, how would i make a heatmap from this? (rounding is not a good option)
Some sample data can be found here. They were created from an original 21x21 array (see below).
Some background
Originally, the data were in a table indexed by integers. It was basically a polar stereographic projection of the lunar surface. So i converted the indices to (x,y) distances then to planetocentric (latitude,longitude) pair and then to gnomonic polar coordinates recentered on a different point than one of the poles. I want to display the map as distance (x axis) and azimuth (y axis) (from the new centered point) and some value (the coloring of the map). The goal is to have something that looks like this:
The sample data you link to is highly structured, but not on an orthogonal grid. That is likely to produce artifacts. If the data were dense enough, you could simply draw each point as a solid block, perhaps with partial transparency. The example data you show is not very dense, however, so this is probably not suitable. I show such a plot below for reference.
set palette defined ( 0 "blue", 3 "green", 6 "yellow", 10 "red" )
set autoscale noextend
set pointsize 2
unset key
plot 'DT0C2.dat' using 1:2:3 with points pointtype 5 lc palette
The closest gnuplot has to dealing with unstructured sample is the dgrid3d mode. This basically uses the data points to assign value to nearby nodes on an orthogonal grid. Various weighting schemes are available to control how many data points contribute to each node and what is their relative contribution. The result is strongly dependent on choosing reasonable values for the orthogonal grid spacing and the weighting scheme. I won't attempt to describe all the options here. Please read the gnuplot documentation section on set dgrid3d. Here is a rough stab at it but I would want to understand the data a lot better to choose a good dgrid3d scheme. I think the sample data is not dense enough to produce a smooth result.
set palette defined ( 0 "blue", 3 "green", 6 "yellow", 10 "red" )
set autoscale noextend
set dgrid3d 75,75 gauss 100,25
set view map
splot 'DT0C2.dat' with pm3d
Related
I am plotting something like 40 plots on the same figure in gnuplot 5. The standard palette quickly runs out of colors, so that it's impossible to distinguish which plot is which. An example (with 10 plots instead of 40, for clarity) is below
If I could tell gnuplot to change dashtype as it runs out of colors, I would easily be able to tell the plots apart. How can I do that?
Nota Bene: the linetype behaviour changed in gnuplot 5. Commands that work in gnuplot 4 will probably fail in gnuplot 5.
A possible solution is to change the dashtype every eight plots. In a plot for command, this can be done like this:
plot for [i = 70:80] 'run'.i.'/e2e.txt' every 1 u 1:2 w l t ''.i dashtype i/8
this works, but the dashtype used are the 7 and 8 ones, which are quite similar to each other and hard to tell apart. Also this is a manual way of fixing it, and therefore error-prone and has to be re-engineered every time I plot something different. Ideally, I would like to change the default linestyle so that the change is performed automatically.
I'm posting the answer here to share a possible solution, in case someone needs it before a better one is provided.
In gnuplot you have color, linewidth (lw), dashtype (dt), pointtype (pt), pointsize (ps) as differentiators.
In your noisy and crowded plot, I would say pt, ps and lw are pretty much out of question.
Distinguishing 40 colors in a graph would be a challenge even for non-color-blind people.
My guess is that you want a quick overview about these curves to "quickly" check how the curves behave (like finding some outliers or different shape or max or min values).
As you said: color and dashtype remain.
In your answer you went for the standard 8 gnuplot colors and 5 dashtypes. You already noticed that some dashtypes are hard to differentiate, depending on the linewidth and graph size.
Well, if you are using an ineractive terminal then you could always zoom in and differentiate the dashtypes (or maybe even pointtypes).
The example below uses 20 colors and 2 dashtypes via a defined palette. Two neigbouring curves have a different dashtype to have a clear differentiatior. The code can easily be changed, e.g. to 10 colors and 4 dashtypes.
Script:
### attempt to display 40 different distinguishable curves
reset session
N=40
# create some random test data
set print $Data
do for [b=1:N] {
y0 = rand(0)*300+100
do for [r=1:200] {
print sprintf("%d %.1f",r,y0=y0+rand(0)*10-5)
}
print ""
print ""
}
set print
set palette defined (0 "red", 1 "green", 2 "blue", 3 "magenta", 4 "yellow", 5 "cyan", 6 "black") maxcolors 20
set key out
set cbrange [0:40]
set cbtics 0,4,40
set mcbtics 4
# unset colorbox # uncomment this line if you want to remove colorbox
plot for [i=1:N] $Data u 1:2:(column(-2)) index i-1 w l lc palette lw 1.4 dt dt=((i+1)%2)*2+1 ti sprintf("%d",i)
### end of script
Result:
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!
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)
I want to plot a histogram like chart with boxes. And I hope the bars have different colors. I found some previous cases, use lc rgb variable, but it doesn't work for me. My version is limited to gnuplot4.2. Here is my data sheet:
stage 11402.364 100% 1
App1 78.552 0.69% 2
App2 11323.812 99.30% 2
Read 8.469 0.07% 3
Write 41.285 0.04% 3
Repeat 5748.351 50.41% 3
Count 4933.746 43.27% 3
Count_1 3841.355 33.69% 4
Count_2 1092.391 9.59% 4
Here is the code part:
set boxwidth 0.5 relative
set style fill solid 0.5
set xtics rotate
plot 'histogramdata_2.txt' using 2:xtic(1):4 with boxes variable lc rgb variable notitle
I want to use the 4th column to denote the bar color. The document said the third number used in using is just the color variable. But it doesn't work for me, the result is no bar produced.
It seems that the using part is quite flexible. I even find some cases in this site put 4 column numbers after using.
It is related to different versions?
Your plot command seems to be wrong. Try the following:
set boxwidth 0.5 relative
set style fill solid 0.5
set xtics rotate
plot 'histogramdata_2.txt' using 0:2:4:xticlabels(1) with boxes lc variable
It should look like this:
In short about the using 0:2:4:xticlabels(1) part:
0 tells gnuplot to place bars (x value) in the same order as they appear on the file
2 tells gnuplot to take y values from column 2
4 tells gnuplot to take the color variable from the 4th column
xticlabels(1) tells gnuplot to take the text labels for the bars from column 1
I have several files that I would like to plot in 2D without interpolation (i.e. a heat map). The data is in three columns (not as a matrix):
#Example data
0 0 1
0 1 -1
0 2 10
1 0 -2
1 1 -0.1
1 2 20
I am using the following commands (Version 4.4):
set pm3d map
set palette rgbformulae 22,13,-31
plot "file" us 1:2:($3>=0?0:$3) notitle w image
which produces the following image:
However, what I would like is:
Ensure that all (column 3) values less than zero will follow the color palette
Ensure that all (column 3) values greater than or equal to zero are white
The color bar does not contain white
I want the image to look like this:
Note, that this is only an example. In my real data, the values that are greater than or equal to zero are dispersed throughout the data. I've been playing around with this all morning but have yet to come up with a solution. Any suggestions would be greatly appreciated.
This is achieved by setting those values to NaN:
set view map
set palette rgbformulae 22,13,-31
plot "file" us 1:2:($3>=0?NaN:$3) notitle w image
This method works only with some terminals (see the discussion at Transparency for specific values in matrix using Gnuplot while preserving the palette?): It works at least with wxt, pdfcairo, pngcairo and png. It does not work with at least x11 and postscript.
The result with 4.6.3 is:
This is my first time trying to use gnuplot, and I can't find any instructions on how to accomplish this. The closest I found was this:
http://gnuplot.sourceforge.net/docs_4.2/node259.html
plot 'file.dat' using 1:2:3:4 with vectors head filled lt 2
but I can't find any explanation about "file.dat".
So can somebody give a simple example of how to draw a simple 2d vector arrow? Thanks.
gnuplot has a very good help/documentation build in. Just type help plot or help vector to learn more on how to plot vectors in gnuplot.
The 2D vectors style draws a vector from (x,y) to (x+xdelta,y+ydelta).
A small arrowhead is drawn at the end of each vector.
4 columns: x y xdelta ydelta
This means, your input file should have 4 columns, where the first two columns define the starting (x,y)-position of the vector/arrow and the last two its (x,y) direction:
# file.dat
0 0 .5 .5
0 1 -.5 .5
1 1 1 0
Now typing the following command
plot "file.dat" using 1:2:3:4 with vectors filled head lw 3
gives the following output:
Drawing vectors with the set arrow command
Consider using the set arrow command, if you only need to draw a few vectors/arrows (e.g. to highlight some points in the plot).
set arrow 1 from pi/2,1 to pi/2,0
set arrow 2 from pi*3/2,-1 to pi*3/2,0
plot[0:2*pi] sin(x)
You can create 'file.dat' in a spreadsheet save it as text and put it in the path of gnuplot by using the cd command to point gnuplot to its location. If that does not agree with you, look at the examples using '+' and '++' and '-' in the gnuplot manual. These are a "virtual data file." Note that the first two are for one and two column data points i.e. (x) or (x,y). You will have to use $1 and $2 as variables for calculating dx and dy. It is obligatory to set the xrange and yrange variables and the isosamples for density for this to work.
Something like....
set isosamples 30
set samples 30
set xrange [-10:10]
set yrange [-10:10]
plot '++' using 1:2:(0.1*sin($1)):(0.1*cos($2)) with vectors