I saw this graph and only for the curiosity sake was wondering whether it was possible to plot figure with multiple y-axis as in the figure
Many thanks!
As andyras wrote, you can use the second y-axis if you only have two datasets. In this case, you also need to to
set ytics nomirror # remove the tickmarks of the left ayis on the right side
set y2tics # make the right y-axis 'visible'
If you want to plot more than one dataset, I would suggest to use multiplot. You can overlay several independent plots and put a unique offset to the y-axis for each of them.
However, you need to take care that the number of y-tics and y-tick positions is the same.
Plot:
(I did not care about the key here, this still needs adjustment)
Code:
set multiplot
set xrange[0:10]
# We need place to the left, so make the left margin 30% of screen
set lmargin screen 0.3
##### first plot
set ytics 0.4
set yrange[-1.2:1.2]
set ylabel "Voltage" textcolor rgb "red"
plot sin(x)
##### Second plot
set ytics 1
set yrange[-3:3]
set ytics offset -8, 0
set ylabel "Current" offset -8, 0 textcolor rgb "green"
plot 3*cos(x) linecolor 2
##### Third plot
set ytics 0.5
set yrange[-1.5:1.5]
set ytics offset -16, 0
set ylabel "Power" offset -16, 0 textcolor rgb "blue"
plot 3*sin(x)*cos(x) linecolor 3
unset multiplot
Yes, you can have two y axes for free, e.g.
plot x, x**2 axes x1y2
The axes specification lets you put things on x1y1, x2y1, etc. If you want more than two things plotted on the same y axes you have to normalize things yourself:
plot 'data1.dat' using 1:($2/MAX_1), \
'data2.dat' using 1:($2/MAX_2), \
'data3.dat' using 1:($s/MAX_3)
The variables MAX_X can be precalculated by using the stats command in gnuplot 4.6+, or you can put them in manually.
Related
I am trying to plot an inlet graph which is shown in Figure. Being an inlet graph it is needed to show x tics and y ticks of relatively big sizes for clear visibility. But when I increase the fonts as,
set xtics font ", 40"
tics overlaps with axis. I increased the plot size set term png size 1000, 1000 but still the issue persists. Kindly suggest if there is a way to move the tics below or to a desired position in graph.
Edit:
The gnuplot script looks like this,
set term png size 1000, 1000
set output "b_vs_N.png"
set style fill solid
set style circle radius 0.001
FIT_LIMIT=1.e-14
set yrange [0.15:0.25]
set style fill solid
set style circle radius 0.001
set xtics 10
set ytics 0.03
set border 15 back lw 6
set xtics font ", 40"
set ytics font ", 22"
set ylabel "b" enhanced font "1 {,40}"
set xlabel "N_i" font "1 {,40}"
set lmargin 12
set bmargin 4
set palette model HSV
set palette rgb 3,2,2
set palette maxcolors 12
set view map
AA(x)=a+b*x+c*x**2
fit AA(x) "data.txt" using 1:2 via c, b, a
plot "data.txt" using 1:2 lt 1 pt 11 ps 2.0 lc rgb "black" notitle, AA(x) w lines lw 2 lc rgb "sienna1" notitle
Your example is uncomplete without code and therefore difficult to reproduce. Please check help xtics. There is the option offset.
Maybe the following example helps to solve your issue.
In the example below no special offset seems to be necessary, i.e. offset 0,0, but you can shift and adjust the labels in x and y direction.
Code:
### tic label offset
reset session
set multiplot
plot sin(x)/x
set origin 0.07, 0.6
set size 0.3,0.3
set xrange [0:10]
set xtics 5 out font ",20" offset 0,0
plot x**2
unset multiplot
### end of code
Result:
I would like to create a color bar plot of a single variable that draws a box to the left in red if the variable is negative and green to the right if positive.
I am failing to get rid of the y axis completely. There shall be no marking of it whatsoever. Second the x-axis and tics is hidden behind the box. I need it visible. Third the plot of the line at 0 is really unnecessary as I have already drawn all I need but gnuplot wants a plot cmd with some sort of argument. I tried plot 0 lt bgnd but that left an ugly white line in my box. I guess I can live with that. Arrows at the ends of the x-axis would be nice, too.
This is the current state of the code. (the variable v will later come from the outside world as command line argument)
v= 7.3
if (v<0){boxcolor= 'red'}
if (v>=0){boxcolor= 'green'}
unset border
unset ytics
unset key
set yzeroaxis
set xzeroaxis
set xtics axis
unset ytics
set xrange [-10:10]
set object 1 rect from 0.0,-0.5 to v,0.5 back fillcolor rgb boxcolor
plot 0
Result currently:
You are probably looking for something like this:
Update: improved version
using graph and first coordinates for the arrow (check help coordinates), hence independent of the actual x-range.
using xzeroaxis (check help xzeroaxis)
Script:
### only x-axis with arrows
reset session
set border 0
unset ytics
v= 7.3
boxcolor = (v<0) ? 'red' : 'green'
set xrange [-10:10]
set xtics axis mirror
set xzeroaxis lt 1 lc "black"
set object 1 rect from 0.0,-0.5 to v,0.5 behind fillcolor rgb boxcolor
set arrow 1 from graph -0.03, first 0 to graph 1.03, first 0 heads filled
plot cos(x)
### end of script
Result:
Another answer: This one uses the built-in axis variants rather than an arrow:
set border 0
unset key
# In newer gnuplot versions there is a keyword "nodraw"
# Here we define a synonym that works with older versions also
hide = -4
set yzeroaxis lt hide lc hide
set xzeroaxis lt black
set tics front
unset ytics
set xtics axis
# define rectangle here
set object 1 rect from 0,-.5 to 5,.5 behind fs noborder fc "green"
#
plot 0 with lines lc "black"
gnuplot adds grid lines even on axes, it can cause unpleasant effects:
set logscale x
set xrange [0.01:100]
set xtics font ",12"
set x2tics font ",12"
set mxtics 10
set ytics font ",12"
set y2tics font ",12"
set grid xtics mxtics ytics lt 0 lw 3, lt 0 lw 0.5 behind
set grid
plot sin(x)
Especially if one then plots the above to eps, it looks like there are both logarithmically spaced and linearly spaced tics on the x-axis. Is there any nice way to get rid of the grid lines at axes? A workaround would be to make the axes thicker, but that is not the way I want. I really want to delete those grid lines.
To explain what I mean
The linearly spaced tics that are seen in the picture are actually the dotted grid, so it has nothing to do with tics...
As shown, there are both log and linear tics along x. That is because both the x axis and the x2 axis are contributing tics to both the top and bottom borders. You can turn that off with
set tics nomirror
Are you asking how to make the range of the tics smaller than the range of the axes? In the plot you show, that would be
set yrange [-1:1]
set ytics -0.8, 0.2, 0.8
set ytics add (-1 2, 1, 2)
The last command adds back explicit tics at y=-1 and y=1 without generating a corresponding grid line. See documentation for set xtics list
I'm using gnuplot to generate some plots with an x axis ranging from 0 to 20. Is it possible to set the color of some tics or axis numbers to a different color from the standard black?
I only found a way to change the color of the all the numbers in the x axis red with set xtics textcolor rgb "red".
What I need is to be able to change the color of the tic or number at x=0,3,6,... to red and all the others should stay black. Is this possible with gnuplot?
The color of the tic marks is set by the border color, so one can do something like this:
reset
set multiplot
set xrange [-5:5]
set xtics -5,1,0 # these tic marks will show up in black (the default border color)
set yrange [] writeback # save auto-generated y range for later
plot sin(x)
set border 0 linecolor "red" # change border color, and turn off drawing of the border
set xtics 1,1,5 textcolor "blue" # these tic marks will show up in the new border color, and we can specify the color of the labels
unset ytics # we don't want to display the y tics again
set yrange restore # use same range for y axis as before
unset key
plot NaN
unset multiplot
This solution also uses multiplot, but uses the second plot only to draw tic marks and labels whose color is different from the default black. It is important that the two plots have the same ranges and margins.
This might be cheating a bit, just create the plot twice with different xtics command on top of each other:
set xrange [0:10]
set multiplot
set size 1,1
set origin 0,0
set xtics 1 textcolor rgbcolor "green"
plot sin(x)
set size 1,1
set origin 0,0
set xtics 1, 2 textcolor rgbcolor "red"
plot sin(x)
unset multiplot
seems to work for me (gnuplot: Version 5.2 patchlevel 2 last modified 2017-11-15)
I have something like:
set grid xtics lt 0 lw 1 lc rgb "#a9a9a9"
set grid ytics lt 0 lw 1 lc rgb "#a9a9a9"
or the same without the "xtics" tag, and that works fine!
But if i add:
unset xtics
Then the grid disappears too :(
How can I only have a grid, without tics?
To hide the major ticks, you can use set tics scale 0:
set grid
set tics scale 0
plot x
Note, if one day you also want to use minor ticks and also hide them, you must use set tics scale 0,0.001.
If you only want to make the tic labels disappear then use set format:
set format x ""
set format y ""
set grid
plot x
If you don't want the tics either, then as far as I know you'd need a more complicated script, possibly using iterators and arrows, for example the following (you'll have to change the limits depending on your xrange and yrange and the arrow style to your liking):
unset xtics
unset ytics
set for [i=-5:5:5] arrow from i,-10 to i,10 nohead
set for [j=-5:5:5] arrow from -10,j to 10,j nohead
plot x