gnuplot histogram: How to hide values on top of bars - gnuplot

After showing some values on top of bars like here. I think thats a good idea. On the other point: Is there is also a way hide some values on the top of bars. Lets say: I have lots of "0", which says nothing in the histogram.

You do not show your specific plot command, so I will assume something similar to the answer you link to. It uses essentially
plot 'data' u 2 with histogram ,\
'' u 0:2:2 with labels font "Helvetica,10" offset -0.9,0.5
You ask how to modify this so that zero values do not produce a label. Here is one possibility. Note that the original answer treats the values in column two as strings for the purpose of "with labels" but we are going to change this to treating them as numbers so that we can test against 0.
filter(col) = (column(col) == 0) ? "" : sprintf("%.1f", column(col))
plot 'data' u 2 with histogram ,\
'' u 0:2:(filter(2)) with labels font "Helvetica,10" offset -0.9,0.5

Related

How to plot data with lines like "<text> <datetime>", with gnuplot?

My data is a typical CSV-like text where each line consists of two columns where the first is text and the second a unix timestamp, as follows:
Mom 1441008169
Dad 1442516527
Ken 1441783871
...
<text> <unix-timestamp>
I thought I could arrange the data along a timeline, drawing dots/shapes of color corresponding to the text in the line, at a point along the x axis corresponding to the timestamp. At best I got gnuplot to tell me:
line 0: Need using spec for y time data
when I tell it to:
set ydata time
set timefmt "%s"
plot "-"
<data>
EOF
I want to render a plot using dots, or diamonds or shapes with color corresponding to the text string in first column. In other words, if my text values fall within the set {"Mom", "Dad", "Ken"}, then gnuplot should draw these shapes corresponding to "Mom" in red, "Dad" in green, and "Ken" in blue, or something like that, at points corresponding to their respective timestamps along the x axis.
The challenge for me is to have gnuplot distinguish between the text strings. The data can be thought of as, for instance, incoming calls from a person where the timestamp indicates date and time for the call and text represents the person calling. I thought representing these data as plotted dots/orbs/diamonds/whatever of different color along a time line would be a good idea, visually.
How would I achieve that? I can, optionally, generate some sort of identifier table where the unique text strings are each equated to a unique sequential generated ID, if that helps gnuplot.
I guess what you want is something like this
The x-axis spans the time interval which is specified by your data file (2nd column). Each name (Ken, Mom, Dad) is represented by a different point type (pt) and a specific colour (lc rgb 'color').
You can generate this plot by the following commands (assuming your data file's name is 'test'):
set xdata time
set timefmt "%s"
set format x "%d/%m/%y"
set xtics rotate
unset ytics
set yrange[0:2]
plot 'test' u ($2):(stringcolumn(1) eq "Ken" ? 1 :1/0) w p pt 5 ps 1.5 lc rgb 'blue' t 'Ken',\
'' u ($2):(stringcolumn(1) eq "Dad" ? 1 :1/0) w p pt 7 ps 1.5 lc rgb 'red' t 'Dad',\
'' u ($2):(stringcolumn(1) eq "Mom" ? 1 :1/0) w p pt 3 ps 1.5 lc rgb 'green' t 'Mom'
You can use different point types by assigning different numbers to pt. ps specifies the point size.
Another representation I came up with is the following:
You can generate it with:
plot 'test' u ($2):(1):(stringcolumn(1)) with labels t '',\
'' u ($2):(0.95) with impulses t ''
I hope this answers your question, and it is what you were looking for.

plot multiple curves with color based on a color map in GNUPLOT

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)

Gnuplot: How to make a 3d palette using the given cordinates and then colour it with a parameter

The question which i have asked may seem too obvious but it is not. I have a file containing X Y Z and a parameter (for example lets say pressure). Now i want to plot the 3d body (just use the command splot "file.dat" u 1:2:3 ) but then here comes the tricky part. I want to color the body using the fourth column, that is pressure. That is where the pressure is maximum u get a red color over the body and where the pressure is minimum u get a blue color over the body. Hope am clear to u all
Use something like
set palette defined (0 'blue', 1 'red')
set autoscale cbfix
splot 'file.dat' using 1:2:3:4 palette
to color the points depending on the fourth column.

Gnuplot transform x axis data with in the plot

I have data in this format
apple 1
bananna 3
ornage 5
fig 4
I want the x axis data to appear in the plot and not in the axis as such. Moreover they are words and not numbers.
How can I do it please?
The question is a bit unclear. Where do you want the labels to show up? Here's an example where I'll put the label "apple" at the point (0,1) and the label "banana" at the point (1,3), etc. (each label is moved 1 unit further down the x axis):
plot 'data.dat' using (column(0)):2:1 with labels
You can also put points associated with it:
plot 'data.dat' using (column(0)):2 w p,\
'' using (column(0)):2:1 w labels
Here the labels sit directly on top of the points. That may not be what you want -- You can add an offset:
plot 'test.dat' u (column(0)):2:1 w labels offset character 0,1,\
'' u (column(0)):2 w p
From the documentation (help labels), it appears that the appearance of your labels should be able to be modified by pretty much any option that you can pass to set label.
The font, color, rotation angle and other properties of the printed text
may be specified as additional command options (see `set label`).

Y-value on bar graph in gnuplot?

Can I get gnuplot to display the exact y-value or height of a data point (plotted using "with boxes") over its bar? I would like the plot to be easy to read so nobody has to line up the top of a bar with the y-axis and guess what the value is.
You can use the labels style and combine it into the plot command with the boxes style. The labels style expects 3 columns of data - the x coordinate, the y coordinate, and the actual label text.
For example, with the following data
1 4
2 6
3 2
4 8
the command (we set the yrange to 0 - 10 and boxwidth to 0.9 and set a solid fill style)
plot datafile u 1:2 with boxes, "" u 1:2:2 with labels offset char 0,1
produces
Normally, the labels would be centered on the specified point (the top edge of the box). By specifying an offset, we can move them up to just above the box. Here we used no offset in the x direction, but a unit of 1 in the y direction. We used the character coordinate system, so this corresponds to moving up by one character unit.
I can only think of putting the values where you want them "manually" like this:
set label "value" at 12,34
The numbers are coordinates according to your x and y ranges.
An automatic way would use "with labels", see e.g.
http://gnuplot.sourceforge.net/demo_4.4/stringvar.html

Resources