I am using multiplot to plot four graphs. My code is given below
set term postscript eps enhanced color
set pm3d map
set pm3d corners2color c1
set size square
set out 'defect2.eps'
unset colorbox
set colorbox horiz user origin 0.1,0.7 size 0.8,0.02
set cbrange [-1.6:0]
set xtics 25
set ytics 25
set lmargin at screen 0.1
set rmargin at screen 0.9
set multiplot layout 1,4
set xlabel "i" font "Times-italic,20"
set ylabel "j" font "Times-italic,20"
spl 'defect.dat' notitle
unset ylabel
spl 'defect_2.dat' notitle
spl 'defect_3.dat' notitle
spl 'defect_4.dat' notitle
unset multiplot
set out
This produces a following plot
However, individual plots in the picture are not properly placed. I cannot see ylabel for the first plot as it is hidden behind the screen whereas there are large blank gaps between those plots. Is there any way to reduce these gaps, increase size of these plots and show the labels properly?
Thanks in advance.
The Problem is your margin setting. The margin defines the size of the white stripe between the box containing the plot and the border of the window.
This means, tic and axis labels are printet on the Martin area! And your 10% of window width is not enough, so the labels are clipped.
So you can adjust the margins to shift all plots more to the left or adjust label font sites and offsets (Miguel's comment).
Related
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 posted a question previously about plotting multiple 3D surfaces together as a multiplot. I got the solution for that but now I am having issue with controlling the fonts of the graphs.
The fonts are terrible in multiplot and My settings are not doing anything with them
I don't know how to control these fonts. I tried ztics but it does not change anything
Here is my code:
set terminal png size 2000,1600 enhanced transparent
set encoding utf8 #iso_8859_1
set output 'output.png'
set border linewidth 2
set pm3d border lw 2
####Set the Axis and Axis-Labels Formatting####
set format '%g'
set xtics font "Helvetica,26" scale 3 # Font for xtics
set xtics offset 3,-1.5 # Put xtics away from the axis
set ytics font "Helvetica,26" scale 3
set ytics offset 3,0 # Put ytics away from the axis
set ztics font "Helvetica,26" scale 3
set ztics 5 # Difference between numbers on Y-axis
set format z "" # To hide ztics on the left side
set grid # Show gridlines on both axis
set pm3d interpolate 1,1
unset key
###---Plot the Graph###---
splot "plastoquinone-scan-a3-formatted.txt" with pm3d # For a single plot
#----------------#
# Set Multiplot #
#----------------#
#set multiplot layout 3,3
#splot "plastoquinone-scan-a1-formatted.txt" with pm3d
#splot "plastoquinone-scan-a3-formatted.txt" with pm3d,
#splot "plastoquinone-scan-b1-formatted.txt" with pm3d,
#splot "plastoquinone-scan-b2-formatted.txt" with pm3d,
#splot "plastoquinone-scan-b3-formatted.txt" with pm3d,
#splot "plastoquinone-scan-c1-formatted.txt" with pm3d,
#splot "plastoquinone-scan-c2-formatted.txt" with pm3d,
#splot "plastoquinone-scan-c3-formatted.txt" with pm3d
Please suggest how can I control the settings for fonts in multiplot and how can I control the fonts of the "key" appearing on the right side (circled red in figure).
I am unable to insert the links of the input files due to less reputation :(
Thanks for your help.
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 want to plot two charts (reading the same data points) using multiplot. The purpose is to put the second (smaller) chart in the right of the first (bigger) chart.
The code is
set term post eps enhanced color blacktext size 4,4 solid "Times-Roman" 14
set output 'cla.ps'
set multiplot
# draw bottom and left lines
unset border
unset xtics
unset ytics
set border 3
# increasing the canvas size
set rmargin 50
set tmargin 2
# put the big chart, it will not use the whole space
set origin 0,0
set size 1.2,0.5
plot 'test.txt' u 1 with points lc rgb "black"
# put the small char in the right
set origin 0.6,0.2
set size 0.2,0.2
plot 'test.txt' u 1 with points lc rgb "black"
# always unset multiplot
unset multiplot
Problem is, the second chart is shown in a mirror fashion (horizontal flip). But I didn't such an option. How can I fix that?
That should give you a nice warning explaining that: warning: Terminal canvas area too small to hold plot. Check plot boundary and font sizes.
With set rmargin 50 you set the right margin to be 50 character widths. That applies also to the second plot unless you use e.g. set rmargin -1 to reset it to automatic calculation.
But I don't see any sense to set both the size and the rmargin. Setting the rmargin does not increase the canvas size, like you suggest in your comments.
Here is a working example:
set term post eps enhanced color blacktext size 4,2 solid "Times-Roman" 14
set output 'cla.ps'
set multiplot
# draw bottom and left lines
unset tics
set border 3
# put the big chart, it will not use the whole space
set origin 0,0
set size 0.8,1
plot x**2
# put the small char in the right
set origin 0.75,0.2
set size 0.25,0.3
plot x
# always unset multiplot
unset multiplot
That gives you the output (tested with 4.6.5):
I use gnu plot to draw a multiplot and in my script I set the y label like that:
set ylabel "foobar"
Now every plot in the multiplot has a dedicated y label on their y axis. However, I would like to have only one y label for all the plots in the multiplot and center that label also on the common y axis. How can I do that? The multiplot layout I use is a 7.1 So all the plots have the same y axis.
The simplest way is to make the first plot, then turn off the y label:
set ylabel 'foo'
set multiplot
plot 'data1.dat'
unset ylabel
plot 'data2.dat'
plot ...
unset multiplot
This will make the x-dimension of the first plot different from that of all the other plots, so you may have to play with the margins if you want all the plots the exact same size.
Plot the individual panels of reduced size without labels but with border, tics and title, then define a full-sized panel with labels but without border, tics and title.You may have to plot a dummy function (1/0).
Global label workaround
This is not ideal, but if you desperate like me, you can use a rotated global label + larger left margins:
#!/usr/bin/env gnuplot
label_label_size = 14
set terminal png
set output "gnuplot.png"
set multiplot layout 2,1 title "Multiplot with one ylabel" font ",18"
set lmargin 10
set label "My y-label" at screen 0.05,0.5 center front rotate \
font "," . label_label_size
plot sin(x)
set xlabel 'My x-label' font "," . label_label_size
plot cos(x)
Here is a realistic application that motivated me to do this: Heap vs Binary Search Tree (BST)
Tested in gnuplot 5.2 patchlevel 6, Ubuntu 19.04.
This is basically the suggestion from Fabian Claremont's answer, but (for beginners) put into code and visualized. Actually, Ciro Santilli's solution is even shorter.
Tested with gnuplot 5.2. For gnuplot 4.6 (the time of OP's question), replace reset session with reset and set margin 8,-1,1-1 with set lmargin 8 and set bmargin 1.
Code:
### Multiplot with single y-label
reset session
unset key
set sample 500
set multiplot layout 7,1
unset ylabel
set linetype 1 lc rgb "red"
set margins 8,-1,1,-1 # left, right, bottom, top (-1=auto)
set ytic 1.0
set title "Plot 1" offset 0,-1
plot sin(1*x)
set title "Plot 2" offset 0,-1
plot sin(2*x)
set title "Plot 3" offset 0,-1
plot sin(3*x)
set title "Plot 4" offset 0,-1
plot sin(4*x)
set title "Plot 5" offset 0,-1
plot sin(5*x)
set title "Plot 6" offset 0,-1
plot sin(6*x)
set title "Plot 7" offset 0,-1
plot sin(7*x)
set lmargin -1 # automatic lmargin
unset title
set origin 0,0
set size 1,1
set border 0
unset tics
set ylabel "This is a centered y-label"
plot [][0:1] -1 # plot a dummy line out of range
unset multiplot
### end of code
Result: