I have generated the code in gnuplot:
set key box bottom right width 2 height 1
set format x "10^{%L}"
set format y "10^{%L}"
set xrange [10**(-4):10**12]
set xtics 10**1
set yrange [10**8:10**31]
set ytics 10**1
set ylabel 'Pressure erg cm^{-3}' font 'Times-Italic,14'
set xlabel 'Density g cm^{-3}' font 'Times-Italic,14'
set logscale x
set logscale y
plot '10.dat' u 1:2 with lines title 'T=1e10',\
'9.dat' u 1:2 with lines title 'T=1e9',\
'8.dat' u 1:2 with lines title 'T=1e8',\
'7.dat' u 1:2 with lines title 'T=1e7',\
'6.dat' u 1:2 with lines title 'T=1e6',\
'5.dat' u 1:2 with lines title 'T=1e5'
to produce such a graph:
But, I would like to reduce the number of labels on x and y axis so I can get sth like this:
Are there some simple ways to do that?
Well, you are explicitly setting the tic distances to 10. In the gnuplot console type help xtics.
Try the following:
set xrange [1e-4:1e12]
set xtics 1e-3, 100
set yrange [1e8:1e31]
set ytics 1e9, 1000
Addition:
Check help xtics. You can place the tics "semi-automatically".
Code:
### "semi-automatic" tics
reset session
set xrange[1e-4:1e12]
set logscale x
set format x ""
set xtics 10
set yrange[1e8:1e31]
set logscale y
set format y ""
set ytics 10
do for [i=-3:12:2] {
set xtics add (sprintf("10^{%d}",i) 10**i)
}
do for [i=9:30:3] {
set ytics add (sprintf("10^{%d}",i) 10**i)
}
plot 1e12*x
### end of code
Result:
Related
I am having a series of problems when defining the axes in my graphic and I would like to share it with you to see if among all we can find the error
I have found on this website a user who has made it similar. My idea is to have one axis on the left and two on the right. But for some reason, it's probably silly, it does not appear correctly.
My code is as following:
set terminal postscript eps enhanced color "Times-Roman" 15
set output "TC_8.eps"
set multiplot
set xlabel "Temperature/{/Symbol \260} C"
set xrange [0:1500]
set key off
set autoscale y
set autoscale y2
##### first plot
set yrange[0:15]
set ylabel "Thermal Diffusivity/(mm^2/s)" textcolor rgb "red"
plot "dt8.txt" using 1:2 smooth cspline lc rgbcolor "red"
##### Second plot
set y2range[0:40]
set y2tics nomirror
set y2label "Thermal Conductivity/ (W/m K))" offset 8, 0 textcolor rgb "green"
plot "dt8.txt" using 1:4 axes x1y2 smooth cspline lc rgbcolor "green"
##### Third plot
set y2range[0:2]
set y2tics no mirror
set y2label "Specific Heat/ (J/(g K))" offset 16, 0 textcolor rgb "blue"
plot "dt8.txt" using 1:3 axes x1y2 smooth cspline lc rgbcolor "blue"
unset multiplot
and the data series is very simple
20 11.466 0.733 28.894
499.6 6.338 1.119 24.38
998.9 5.3 1.292 23.542
1499 4.639 1.645 26.247
The problem is that the two axes on the right do not appear correctly, and the data lines ... either.
Thanks in advance
Do not hesitate to append your plot result and give the reference where you have found something similar.
One way might be to change the margins of the graph and plot another dummy graph just for the third (separated) axis. By the way, you can put two datalines into one plot.
Code: (edit: modified to make it copy&paste including data)
### 3 y-axes
reset session
$Data <<EOD
20 11.466 0.733 28.894
499.6 6.338 1.119 24.38
998.9 5.3 1.292 23.542
1499 4.639 1.645 26.247
EOD
set key off
set autoscale y
set autoscale y2
set lmargin 10
set tmargin 2
set bmargin 4
set rmargin 20
set multiplot
##### first plot
set xlabel "Temperature / {/Symbol \260}C" font ",11"
set xrange [0:1500]
set ylabel "Thermal Diffusivity / (mm^2/s)" textcolor rgb "red" font ",11"
set yrange[0:16]
set ytics nomirror
set y2range[0:40]
set y2tics nomirror
set y2label "Thermal Conductivity / (W/m K)" offset -1,0 textcolor rgb "green" font ",11"
set grid xtics, ytics
plot $Data u 1:2 axes x1y1 smooth cspline lc rgbcolor "red", \
'' u 1:4 axes x1y2 smooth cspline lc rgbcolor "green"
##### Second plot
unset xlabel
unset ylabel
unset y2label
unset tics
set y2range[0:2]
plot $Data u 1:3 axes x1y2 smooth cspline lc rgbcolor "blue"
##### Third plot
set rmargin 10
set border 8 # only right border visible
set y2label "Specific Heat/ (J/(g K)" offset -1,0 textcolor rgb "blue" font ",11"
set y2tics nomirror offset 0,0
plot NaN # plot nothing
unset multiplot
### end of code
Result:
How can I add an X grid with different spacing than the tics? My plot is a histogram showing # of patents (of a certain type) granted per year, and the year range is large (1807-1971). I'd like to tic/label each year but only add X grid lines every decade (and also use a different color for the matching decade labels).
I've been searching for an answer and trying things for hours and getting nowhere. Are either of these possible?
My current plot (with no X grid) looks like:
And the script is:
set style data histograms
set style histogram gap 1
set style fill solid
set title "Number of Prism Glass Patents Granted" font "fixed, 24" offset 0,-0.9
set xlabel "Year" font "fixed,18" offset 0,0.8
set nokey
set xtics out nomirror rotate font "fixed, 8" offset 0,0.4
set grid y
plot 'frequency.dat' using 2:xtic(1) linecolor 'blue'
I assume your data consists out of two columns: Year and number of patents.
Why do you use xitc(1), is it necessary to label every single year?
What about using minor and major xtics? I would use plotstyle with boxes.
Code:
### major and minor xtics
reset session
# generate some random data
set print $Data
do for [i=1807:1971] {
print sprintf("%d %d", i, int(rand(0)*100))
}
set print
set xlabel "Year"
set xtics out nomirror
unset x2tics
set xtics 10
set mxtics 10
set grid ytics
set grid xtics
set boxwidth 0.5
plot $Data u 1:2 with boxes fill solid 1.0 lc rgb "blue" notitle
### end of code
Result:
Addition:
Another version with grid every 10 years and label with different color. Labels are only shown when number of patents>0. Instead of using xtics it is done by plotting with labels.
Code:
### major and minor xtics
reset session
set term pngcairo size 1600,360
set output "tbGrid.png"
xmin = 1807
xmax = 1971
# generate some random data
set print $Data
do for [i=xmin:xmax] {
print sprintf("%d %d", i, int(rand(0)+0.4)*(int(rand(0)*100)))
}
set print
set xlabel "Year" offset 0,-1.5
set xrange[xmin-1:xmax+1]
set xtics 10 format "" out nomirror
set mxtics 10
set bmargin 5
set grid ytics
set grid xtics
set boxwidth 0.5
myTic(n,p) = p==0 ? "" : sprintf("%d",n)
myColor(n) = int(n)%10==0 ? 0xff0000 : 0x000000
plot $Data u 1:2 with boxes fill solid 1.0 lc rgb "blue" notitle, \
'' u 1:(0):(myTic($1,$2)):(myColor($1)) with labels \
tc rgb var rotate offset 0,-1.5 font ",8" notitle
set output
### end of code
Result:
The grid for each axis is generated from the tics for that same axis, so yes they always match. However if your plot uses only the x1 axis, you could define the range and tics for the x2 axis also and turn on the grid only for x2 and not for x1.
Recent gnuplot versions have a command set link x2 that ensures the x1 and x2 axes agree on the range and scale. If your version does not support this you can still set them to match explicitly:
set xrange [min:max]
set x2range [min:max]
set xtics <whatever> # these will label the actual plot
set x2tics <something else> # these will be used only for grid lines
set x2tics scale 0.0 format "" # show no x2 tics or labels on the plot
set grid x2 nox
plot ...
Thank you both-- here's my final plot:
...and its script:
# histogram of # of prism glass patents granted per year
###
set term png size 1800,600
xmin = 1807
xmax = 1971
set title sprintf("Prism Glass Patents Granted %d-%d", xmin, xmax) \
font "fixed, 24" offset 0,-0.5
set xlabel "Year" font "fixed,24" offset 0,-2
# x tic for each year
set xrange [xmin-1:xmax+1]
set xtics 1 out nomirror format ""
# x2 tic and gridline for each decade
set x2tics 1800,10,1970
set x2tics out font "fixed, 12" offset 0,-0.6
set grid x2 nox
set grid y # y axis is count
set boxwidth 0.5
set bmargin 5
set nokey
myTic(y,n) = n==0 ? "" : sprintf("%d",y) # only label year if count>0
myColor(y) = y==1897 ? 0x0000FF : 0x000000 # highlight 1897 (biggest year)
plot 'frequency.dat' using 1:2 with boxes fill solid lc rgb "blue", \
'' using 1:(0):(myTic($1,$2)):(myColor($1)) with labels \
tc rgb var rotate offset 0.1,-1.2 font "fixed,8"
I want to plot multiple files using a Gnuplot script.
However, I'm having some trouble to make it perfect.
My actual plots are something like that:
However, the linepoints plot is touching both the x-axis and the y-axis.
Therefore, I want to add extra space on xrange and yrange and get
which does not touch my axis.
I could to it manually using set xrange and set yrange.
However, I need to plot more than 100 different files, and it will be very time-consuming to do so.
There is some manner to automatically increase the size of xrange and yrange by some units?
My Gnuplot code is below.
#!/usr/bin/env gnuplot
set terminal epslatex size 7.5,3 standalone
set output 'pareto.tex'
set style fill solid 0.8
set ytics nomirror
set xtics nomirror
set grid lc rgb "#F2F2F2"
set xlabel 'Z_1'
set ylabel 'Z_2'
set xrange [170:215]
set yrange [7:40]
set style line 1 lt rgb "#000000" lw 12 pt 7 pointsize 3
plot "../exact.dat" using 1:2 title '$aug\,\epsilon$-CM' with linespoints ls 1
unset output
set output # finish the current output file
system('pdflatex --interaction=batchmode pareto.tex')
unset terminal
system
The command you are looking for is set offset. See the documentation for a full description.
Example:
set multiplot layout 3,1
# Default placement
plot 'silver.dat' with lines
# Additional whitespace combined with auto-extenstion to nearest ticmark
set offset 20,20,20,20
replot
# Additional whitespace with no auto-extension to nearest ticmark
set xrange [*:*] noextend; set yrange [*:*] noextend
replot
unset multiplot
Following is the code I use and below that is my output. I want to remove all the spaces in between my subplots and the x labels. A sample of what I need is provided in the link at the end the only difference being I need all the boxes to be of same size.
set terminal jpeg
set output "mul.jpeg"
set multiplot
set xr[0:10]
set ylabel "y"
set format y ""
set key off
set size 1,0.25
set origin 0.0,0.0;
set xlabel "x"
plot sin(x)
replot sin(2*x)
set origin 0.0,0.25;
set format x ""
plot cos(x)
replot cos(2*x)
set origin 0.0,0.50;
set format x ""
plot sin(x)
set origin 0.0,0.75;
set format x ""
plot cos(x)
unset multiplot
What I actually need is something like this:
https://inspirehep.net/record/1345236/files/hada_fig2.png
Thank you for any help!
From gnuplot 5.0, you can use the solution offered by #Raphael_Roth of setting margins to zero, but should also use the margins option of multiplot, to allow space for the tic labels and xlabel at the bottom.
E.g,
set tmargin 0
set bmargin 0
set lmargin 1
set rmargin 1
set multiplot layout 4,1 margins 0.05,0.95,.1,.99 spacing 0,0
set xrange [0:10]
unset xtics
plot sin(x), sin(2*x)
plot cos(x), cos(2*x)
plot sin(x)
set xtics
plot cos(x)
unset multiplot
One way is to use multiplot layout, but it's a hassle to get it nice with the labels and tics (as they overlapp or don't fit into the canvas)
set terminal jpeg
set output "mul.jpeg"
set tmargin 0
set bmargin 0
set lmargin 1
set rmargin 1
unset xtics
unset ytics
set multiplot layout 4,1
set xr[0:10]
plot sin(x), sin(2*x)
plot cos(x), cos(2*x)
plot sin(x)
plot cos(x)
unset multiplot
The other possibility is to set the margins and/or origin of each plot separately as explained in these SO answers: multiplot - stacking 3 graphs on a larger canvas and How do gnuplot margins work in multiplot mode?
I want to draw xtics on top but without its tic labels:
This is what I want:
This is the code I tried:
set xtics mirror;
set border 2+4;
plot x;
This gave me:
How can I modify the script to get what I want?
You can remove the tick labels with set format x '', but that still leaves the xtics at the bottom.
In my opinion, the best way is to use only the x2-axis
set ytics nomirror
unset xtics
set x2tics nomirror
set format x2 ''
set border 2+4
plot x axes x2y1
you can make the color of the font as the background color e.g. for white background
set xtics out offset -1.,0 scale 2.2 enhanced font 'Helvetica:bold,45' tc rgb "#FFFFFF"