I have an interactive perl script which uses data from mysql to generate many plots through the Chart::Gnuplot package. There are times when the graph size is overloaded with too many plots.
I would option to generate the gnuplot image containing only the legend (no graph).
I don't know if this would help, but...
plot [0:1] [0:1] NaN title "Hello" #Just the label in the legend.
or...
plot sin(x),NaN title "Boo" #Plots sin(x) (properly labelled) and a second label "Boo"
Of course, this still has the border and other things. You can unset those...unset border and unset tics
Related
My data set is simple:
CPU 5.7
Memory 3.7
I want to plot a simple bar diagram with different colors for each value and the corresponding values should be shown on top of each bar. I also want to plot the ylabel and the legend. It should almost look like the the following diagram:
Is this possible in gnuplot? There seems to be hardly any document for doing this in gnuplot. Plotting bars with historgram seems easy but styling with different colors, the value on top and the legends part is turning out to be a bit tricky for me. Can someone please help me?
Thanks in advance.
Maybe the following comes quite close:
This is the gnuplot script:
set terminal pngcairo
set output "data.png"
set title "CPU and Memory"
set nokey
set boxwidth 0.8
set style fill solid
set xrange [-1:2]
set xtics nomirror
set yrange [0:7]
set grid y
set ylabel "Time"
plot "data.dat" using 0:2:3:xtic(1) with boxes lc rgb var ,\
"data.dat" using 0:($2+0.5):2 with labels
The pseudo column 0, which is the current line number, is used as x value.
I have added a third column to your data which contains the color as rgb value.
The value on top of the bars is printed by the with labels command. It requires a using with three values: x, y, string. The part ($2+0.5) takes the y-value from the second column and adds 0.5.
The identifiers "CPU" and "Memory" are printed below the corresponding bar instead of using a separate key.
And this is the modified datafile:
CPU 5.7 0x4472c4
Memory 3.7 0xed7d31
I am trying to plot three different plots on the same canvas using the multiplot mode of gnuplot (version 5.0.1)
I want an arrangement of these plots in a particular way: final plot should show 2 rows with plot A in the upper row while plots B and C should appear in the lower row side-by-side as if for a lower row we had something like:
"set multiplot layout 1,2"
How can this be achieved?
Thanks in advance
you need to do the multiplot with the most "refined" grid, in this case 2x2 and then specify the size of each plot.
set multiplot layout 2,2
set size 1,0.5 # the first one has to be larger
plot sin(1*x)
set multiplot next # we want to skip the second (upright position)
set size 0.5,0.5 # the second and third have to be 0.5x0.5
plot sin(2*x)
plot sin(3*5)
unset multiplot
or as suggested here https://stackoverflow.com/a/15906085/2743307 it might be simpler to do it upwards (6 lines instead of 8!) but you have to specify the plots in opposite order:
set multiplot layout 2,2 upwards
plot sin(3*x)
plot sin(2*x)
set size 1,0.5
plot sin(1*x)
unset multiplot
Is there a way to change the color of the lines of the surface when using dgrid3d? It seem simple enough but everything I've looked at only speaks of coloring the whole surface using pm3d. I have multiple surfaces on one plot and would like to be able to specify the color of each. For example, one would be red, another would be blue, another would be black, another would be green.
If you have your data available in a file Data.dat then give this a try:
set dgrid3d 10,10
set style data lines
set pm3d
splot "Data.dat" pal
The dgrid3d tells gnuplot how many entries there are in the x- and
y-direction (those are the two comma separated parameters)
The style data lines lets gnuplot plot the result with lines
instead of points
The pm3d fills the surface with a color (if you leave this away you
will just see the lines)
pal makes the lines appear in the color of the specified value
There are much more options you can set, but i find those the most relevant.
Seems like.
set dgrid3d
splot "file.dat" with lines linecolor 4
Where 4 is color you need.
For multiple surfaces you can try
set dgrid3d splines
set table "surface1.dat"
splot "file1.dat"
unset table
unset dgrid3d
for every surface you need.
And after all surface description
splot "surface1.dat" with lines linecolor 4, splot "surface2.dat" with lines linecolor 7 ...
I have two files that has the time as x axis and a value. I need to overlay these two on a single plot. Currently i tried it using GNUplot, but struck in the middle. Here is a sample file
01:03:05 6
01:03:15 6
and another file
01:03:55 6
01:04:10 6
I need to plot these two files (say x mark and some other symbol for differentiation) in a single plot. I dont know if it is possible to do that in GNUplot. Currently I have created two grids for each file. But I need both in a single plot. Here is what I have written
set multiplot layout 1,2 # engage multiplot mode
set xdata time ## these three lines control how gnuplot
set timefmt '%H:%M:%S' ## reads and writes time-formatted data.
set format x '%H:%M:%S' ##
set xtics 05 # make time spacing of 2 minutes
plot 'AAA' u 1:2 # plot the first data set
plot 'BBB' u 1:2 # plot the second data set
unset multiplot
Can anyone familiar with GNUplot or any other tool (working in linux) can help me.
In order to plot multiple lines in a single plot, simply put them in a single plot command like
plot 'AAA' u 1:2, 'BBB' u 1:2
There are numerous examples out there that give you a good start with gnuplot. This one for example shows how to plot multiple lines in one plot.
The multiplot command you are using in your script would also make it possible to have multiple plot windows like shown here. You can adjust the position of each subplot by:
set size XSIZE,YSIZE #see `help set size`
set origin XORIGIN,YORIGIN #see `help set origin`
or (if you have gnuplot 4.2 or newer):
set lmargin at screen XMIN #see `help margin`
set rmargin at screen XMAX
set tmargin at screen YMAX
set bmargin at screen YMIN
I am new to gnuplot and while plotting stacked histogram, I find that legend gets hidden behind the data.
Is there a method to put the legend above the data? Thanks a lot for your help.
EDIT: I am currently using set key outside bottom to place legend outside, but that is not the best solution I would like.
Recent versions allow to make the background of the legend white:
set key opaque
This simply adds a white background to the legend so it appears on top of all graphs. Found the answer in this Post.
If you would rather have the key on top of the data rather than the key outside the plot box altogether, here is one workaround (using sin(10*x) as an example):
set multiplot
unset key
plot sin(10*x) # this will plot with tics and a border, but no key
set key box
unset tics
unset border
bignumber=10 # make this number larger than the y range so the line will not be seen
plot [][0:1] bignumber title 'sin(10*x)' # this will just plot the key with the title
unset multiplot
Using this method, first you plot your data/function, then you create a plot on top of that which just has a key. You have to make sure to set the title of the second plot properly.