how to define X's label on gnuplot - gnuplot

This is My data :
18_AGT_s 8234.00 8234.00 8234.00
18_MAC_s 8414.36 8308.36 8246.33
9_MAC_r 8414.36 8308.36 8246.33
9_MAC_s 8414.55 8309.55 8246.45
8_MAC_r 8414.55 8309.55 8246.45
8_MAC_s 8414.56 8310.08 8246.47
6_MAC_r 8414.56 8310.08 8246.47
6_MAC_s 8416.19 8310.21 8246.49
1_MAC_r 8416.19 8310.21 8246.49
and here is my gnuplot code :
plot "dat" using ($0+1):2 with linespoints pt 8 ps 2 lt 2 lw 4 lc rgb
"green" title "DMSR","dat" using ($0+1):3 with linespoints pt 5 ps 2
lt 3 lw 4 lc rgb "blue" title "Alarm","dat" using ($0+1):4 with
linespoints pt 6 ps 2 lt 4 lw 4 lc rgb "red" title "Emergency"
and here is my out put :
But In the step part I want to have 18_AGT_s and 18_MAC_s and 9_MAC_s and .... for example on the X part I want to have 18_AGT_s in stand of 1 or I want to have 18_MAC_2 instand of 2 and 9_MAC_r instand of 3 etc. Any help thanks

Use the xticlabels() option with the column number with the labels as argument (1, in this case):
# Optionally rotate labels so they fit
set xtics rotate
plot "dat" using ($0+1):2 with linespoints pt 8 ps 2 lt 2 lw 4 lc rgb \
"green" title "DMSR","dat" using ($0+1):3 with linespoints pt 5 ps 2 \
lt 3 lw 4 lc rgb "blue" title "Alarm","dat" using \
($0+1):4:xticlabels(1) with linespoints pt 6 ps 2 lt 4 lw 4 lc rgb \
"red" title "Emergency"
Here you only need to use it for the last plot instance so that it overwrites the number options.

Related

Gnuplot combing multiple value types in one line graph with different colours and dashes

I have three different lines, where colours and their dashes means different things which I want on one plot, instead of three. How do I accomplish that?
set datafile separator comma
$sample <<EOD
2020-01-01,4,UK,Business
2020-02-01,4,UK,Business
2020-01-01,4,UK,Social
2020-02-01,15,UK,Social
2020-01-01,1,USA,Social
2020-02-01,25,USA,Social
EOD
set format x '%Y'
set xdata time
set timefmt "%Y-%m-%d"
plot '$sample' u 1:2 title "UK/Business" with linespoints dt 3 lw 5 pt 7 lc "red"
plot '$sample' u 1:2 title "USA/Social" with linespoints dt 3 lw 1 pt 7 lc "blue"
plot '$sample' u 1:2 title "UK/Social" with linespoints dt 3 lw 5 pt 7 lc "blue"
E.g. blue is "Social" and lw 1 (fine dots) is for USA.
Please check the manual or help plot. Plot elements for the same plot are separated by comma.
Syntax:
plot {<ranges>} <plot-element> {, <plot-element>, <plot-element>}
To improve readability you can split long code lines into several lines by using \. Note that no character is allowed after \ in the same line except carriage return/line feed.
Try this:
plot '$sample' u 1:2 title "UK/Business" w lp dt 3 lw 5 pt 7 lc "red", \
'' u 1:2 title "USA/Social" w lp dt 3 lw 1 pt 7 lc "blue", \
'' u 1:2 title "UK/Social" w lp dt 3 lw 5 pt 7 lc "blue"
Addition: (a filter depending on two (string)-columns)
You can implement a filter by using the ternary operator. Check help ternary and help strcol. A value which does not pass the filter will be set to NaN. If you still want to your points being connected with lines, you need to set datafile missing NaN.
Code:
### filtered data with different line colors
reset session
set datafile separator comma
$sample <<EOD
2020-01-01,4,UK,Business
2020-02-01,4,UK,Business
2020-01-01,4,UK,Social
2020-02-01,15,UK,Social
2020-01-01,1,USA,Social
2020-02-01,25,USA,Social
EOD
myTimeFmt = "%Y-%m-%d"
set format x '%d.%m.%Y' timedate
set key top left
set datafile missing NaN
myFilter(colData,colFilter1,key1,colFilter2,key2) = (strcol(colFilter1) eq key1) && (strcol(colFilter2) eq key2) ? column(colData) : NaN
plot $sample u (timecolumn(1,myTimeFmt)):(myFilter(2,3,"UK",4,"Business")) w lp dt 3 lw 5 pt 7 lc "red" title "UK/Business", \
'' u (timecolumn(1,myTimeFmt)):(myFilter(2,3,"USA",4,"Social")) w lp dt 3 lw 1 pt 7 lc "blue" title "USA/Social" , \
'' u (timecolumn(1,myTimeFmt)):(myFilter(2,3,"UK",4,"Social")) w lp dt 3 lw 5 pt 7 lc "blue" title "UK/Social"
### end of code
or a bit shortened if the columns 2,3,4 do not change within the plot command...
...
...
myTime(col) = timecolumn(col,myTimeFmt)
myFilter(key1,key2) = (strcol(3) eq key1) && (strcol(4) eq key2) ? column(2) : NaN
plot $sample u (myTime(1)):(myFilter("UK","Business")) w lp dt 3 lw 5 pt 7 lc "red" title "UK/Business", \
'' u (myTime(1)):(myFilter("USA","Social")) w lp dt 3 lw 1 pt 7 lc "blue" title "USA/Social" , \
'' u (myTime(1)):(myFilter("UK","Social")) w lp dt 3 lw 5 pt 7 lc "blue" title "UK/Social"
Result:

Gnuplot line and key colors

I'm trying to use Gnuplot to create a line chart. Each line is represented by a different color. What I want is the key has the same color as the line color. This is what I have right now, current version. Is it possible to set the text 'Line 2' colored as orange, 'Line 3' colored as red, etc?
This is what I wrote in the gp file:
set xlabel'x-axis'; \
set xrange[0:25];\
set ylabel 'y-axis';\
set yrange [2:9];\
set key left top;
p 'test.dat' using 1:2 w linespoints lw 5 lc rgb '#aadc32' pt 17 title 'Line 1' ,\
'test.dat' using 1:9 w linespoints lw 5 lc 'orange' lt 1 title 'Line 2',\
'test.dat' using 1:6 w linespoints lw 5 lc 'red' lt 8 title 'Line 3',\
'test.dat' using 1:7 w linespoints lw 5 lc 'violet' pt 6 title 'Line 4',\'test.dat' using 1:8 w linespoints lw 5 lc rgb '#b5367a' pt 19 title 'Line 5',\
'test.dat' using 1:3 w linespoints lw 5 lc 'cyan' pt 9 title'Line 6',\
'test.dat' using 1:4 w linespoints lw 5 lc 'blue' lt 9 title 'Line 7',\
'test.dat' using 1:10 w linespoints lw 5 lc rgb '#1c1044' lt 5 title 'Line 8',\
Thank you so much.
Unfortunately not. The plot title does not (now, gp5.2pl0) recognise the "textcolor" specifier.
plot x lw 3 lc rgb "blue" title "x" tc rgb "blue" # doesn't work
You can only print an empty (" ") plot title, and overprint it with a coloured label
set label 1 at 8,1 "bluetitle" tc rgb "blue"
That requires some fiddling with the placement of the label, of course.
You might put up a feature request on https://sourceforge.net/p/gnuplot/feature-requests/

Gnuplot: color for stacked histogram bars

I want to create this histogram with gnuplot:
I used the 6th example from http://gnuplot.sourceforge.net/demo/histograms.html
datafile has the next structure:
Region Austria Hungary ...
1891-1900 234081 181288 ...
1901-1910 668209 808511 ...
...
https://github.com/gnuplot/gnuplot/blob/master/demo/immigration.dat
The minimal script I've got here
http://gnuplot.sourceforge.net/demo/histograms.6.gnu
Is it possible to set the custom color for periods?
Perhaps not the most elegant solution, nevertheless one could prescribe the colors manually by overriding the default linetypes:
set lt 1 lc rgb 'red'
set lt 2 lc rgb 'orange-red'
set lt 3 lc rgb 'orange'
set lt 4 lc rgb 'yellow'
set lt 5 lc rgb 'green'
set lt 6 lc rgb 'blue'
set lt 7 lc rgb 'dark-blue'
set lt 8 lc rgb 'violet'
plot 'immigration.dat' using 6 ti col, '' using 12 ti col, '' using 13 ti col, '' using 14:key(1) ti col
In combination with your minimal script, this produces:

Set point size independent of line weight

I have the following line styles defined in gnuplot:
set linetype 1 lc rgb "red" lw 3 pt 7
set linetype 3 lc rgb "red" lw 1 pt 7
It appears as though the points derive part of their size from the lineweight. I'm using these styles inside of a plot for loop with linetype cycle using the same style for a cspline and the corresponding points, so I don't see any easy way to just define a separate style for the points.
I get results like this:
The points respond to pointsize but the point in linetype 1 is still slightly larger (presumably from the thicker border).
Is it possible to get the points in these two styles to be the same size?
In response to Miguel's comment, a more complete example of my use case is:
filenames = "A B C D"
set linetype 1 lc rgb "blue" lw 3 pt 7
set linetype 2 lc rgb "red" lw 3 pt 7
set linetype 3 lc rgb "blue" lw 1 pt 7
set linetype 4 lc rgb "red" lw 1 pt 7
set linetype cycle 4
plot for [file in filenames] file.".csv" \
using 1:2
title file \
smooth csplines, \
for [file in filenames] file.".csv" \
u 1:2 with points notitle
linetypes 5-8 get set by the cycling and are used by the last part of the plotting command. Recommendations on another way to do this would be welcome!
For your very specific case you can set more styles, and do it rather automatically with a do for loop (reusing your code):
filenames = "A B C D"
do for [i=0:1] {
set linetype (4*i+1) lc rgb "blue" lw (i == 1 ? 0 : 3) pt 7
set linetype (4*i+2) lc rgb "red" lw (i == 1 ? 0 : 3) pt 7
set linetype (4*i+3) lc rgb "blue" lw (i == 1 ? 0 : 1) pt 7
set linetype (4*i+4) lc rgb "red" lw (i == 1 ? 0 : 1) pt 7
}
set linetype cycle 8
plot for [file in filenames] file.".csv" \
using 1:2 \
title file \
smooth csplines, \
for [file in filenames] file.".csv" \
u 1:2 with points notitle
With some simple data files:
For some terminals the size of filled point types depends on the linewidth because they have a border. This is the case for all cairo-based terminals (pdfcairo, pngcairo, wxt and cairolatex), whereas other terminal like svg, postscript, qt don't show this behaviour.
As test case consider
set linetype 1 lc rgb "red" lw 3 pt 7
set linetype 3 lc rgb "red" lw 1 pt 7
set samples 11
set style function linespoints
plot x lt 1, x + 0.5 lt 3
Considering that you want to have the linepoints samples in the legend, you're best choice is to reduce the point size a bit for the line type with the larger linewidth, like
set linetype 1 lc rgb "red" lw 3 pt 7 ps 0.9
The choice of the scaling factor must be determined manually.

Gnuplot is not ploting anymore

I have a script to plot a graph with gnuplot. Last manth this script was ploting with no errors. I didn't make any modification but now it is not ploting anymore. I did all steps on this web site but still don't work. http://www.gnuplot.info/faq/faq.html#SECTION00092000000000000000
Does anybody have an idea of what is happening?
Thanks!
#!/usr/bin/gnuplot
reset
set grid
set title 'Desempenho do BTRIM com peers de reputação condicionada'
set xlabel 'Tempo'
set ylabel 'Vazão - downloads completos / tempo'
set style line 1 lc rgb '#0060ad' lt 1 lw 2 pi -1 ps 1.0
set style line 2 lc rgb '#dd181f' lt 1 lw 2 pi -1 ps 1.0
set style line 3 lc rgb '#29c524' lt 1 lw 2 pi -1 ps 1.0
set style line 4 lc rgb '#7D72F9' lt 1 lw 2 pi -1 ps 1.0
set style line 5 lc rgb '#000000' lt 1 lw 2 pi -1 ps 1.0
set pointintervalbox 0
plot '<paste ../00/Statistic100.txt ../01/Statistic100.txt ../02/Statistic100.txt ../03/Statistic100.txt ../04/Statistic100.txt ../05/Statistic100.txt ../06/Statistic100.txt ../07/Statistic100.txt ../08/Statistic100.txt ../09/Statistic100.txt' smooth unique with linespoint lt 5 lw 1 title 'Reputação de 100%', \
'<paste ../00/Statistic75.txt ../01/Statistic75.txt ../02/Statistic75.txt ../03/Statistic75.txt ../04/Statistic75.txt ../05/Statistic75.txt ../06/Statistic75.txt ../07/Statistic75.txt ../08/Statistic75.txt ../09/Statistic75.txt' smooth unique with linespoint lt 6 lw 1 title 'Reputação de 75%', \
'<paste ../00/Statistic50.txt ../01/Statistic50.txt ../02/Statistic50.txt ../03/Statistic50.txt ../04/Statistic50.txt ../05/Statistic50.txt ../06/Statistic50.txt ../07/Statistic50.txt ../08/Statistic50.txt ../09/Statistic50.txt' smooth unique with linespoint lt 7 lw 1 title 'Reputação de 50%', \
'<paste ../00/Statistic25.txt ../01/Statistic25.txt ../02/Statistic25.txt ../03/Statistic25.txt ../04/Statistic25.txt ../05/Statistic25.txt ../06/Statistic25.txt ../07/Statistic25.txt ../08/Statistic25.txt ../09/Statistic25.txt' smooth unique with linespoint lt 8 lw 1 title 'Reputação de 25%'
pause -1

Resources