While working on data visualization for an article, it became necessary to have 4 axes with positive labels on all of them.
As for other charts in the article, I decided to use guplot. First of all, I looked at the official website, where there are many examples. I was very happy when I found the right one.
Quickly copied the code, run. I am getting an error. I understand. It turned out that I have an old gnuplot (Version 5.0 patchlevel 3 last modified 2016-02-21
) and he does not know how.
Knowing about the flexibility of gnuplot, I started to rummage around the world wide web and came across some relevant examples on stackoverflow (
Further, my manipulations with commands resulted in the following:
0) Disable
unset border
1) Create 4 zero lines - 2 main and 2 additional:
set xzeroaxis
set yzeroaxis
set x2zeroaxis
set y2zeroaxis
A few words about zero lines in
2) Set up the display of ticks on the axes:
max = 1.5 # ΠΠ»Ρ Π³ΠΈΠ±ΠΊΠΎΡΡΠΈ
min = -max
set xtics axis 0,.5,max in scale 0.5,0.25 mirror norotate autojustify offset 0.35
set ytics axis .5,.5,max in scale 0.5,0.25 mirror norotate autojustify
set x2tics axis .5,.5,max in scale 0.5,0.25 mirror norotate autojustify
set y2tics axis .5,.5,max in scale 0.5,0.25 mirror norotate autojustify
With ticks on the axes, there are a little more settings.
axis
- where the ticks will be located, on the axis or (border - on the border).
For axis x
, which goes to the right 0,.5,max
. The first number is the start of the count, the second is the step, the third is the end of the count. For the first from 0
, and for the rest from 0.5
so that the zeros do not interfere at the origin.
Blending zeros at the center of coordinates.
All intervals *tics
configured as 0,.5,max
Without offset 0.35
for xtics
Setting scale 0.5,0.25 mirror
adds serifs to the axis. If you play with the numbers, their size will change.
I also introduce variables max, min
, with the help of which I control the boundaries of the chart axes.
Additional information on setting up ticks can be found in the documentation in the section
3) Set up the ranges of the axes:
set xrange [ min : max ]
set yrange [ min : max ]
set x2range [ max : min ]
set y2range [ max : min ]
It should be noted here that the 2 axes start from min
for magnification and 2 axes - with max
to decrease.
Additional information in the section
4) We give the axes names and place them nicely:
set label "H_1" at 0, max center offset char 2, 0
set label "H_2" at max+0.1, 0 center offset char -1, 1
set label "H_3" at 0, min center offset char -2, 0
set label "H_4" at min, 0 center offset char 0, 1
5) We form the input data
Each chart has 2 columns. Line number - axis number, fifth line to close the contour. Odd column - coordinate x
, even - y
. In view of the fact that all points are located on the axes, then from the pair (x, y)
one is always zero.
Even though all 4 axes are positive, some data is artificially shifted to the negative half because it is on the main axes x
ΠΈ y
.
0 1 0 1.21
1 0 1.21 0
0 -1 0 -1.06
-1 0 -1.19 0
0 1 0 1.21 #ΠΡΠ±Π»ΠΈΠΊΠ°Ρ ΠΏΠ΅ΡΠ²ΠΎΠΉ ΡΠΎΡΠΊΠΈ
Experience the Power of Effective Results
Full code
#!/usr/bin/gnuplot -persist
#ΡΠ°ΠΉΠ» Π² ΠΊΠΎΠ΄ΠΈΡΠΎΠ²ΠΊΠ΅ cp1251 ΡΡΠΎΠ± ΡΡΡΡΠΊΠΈΠ΅ Π±ΡΠΊΠ²Ρ ΠΎΡΠΎΠ±ΡΠ°ΠΆΠ°Π»ΠΈΡΡ Π² eps
set encoding cp1251
set terminal postscript eps enhanced monochrome size 5cm,5cm
set output "./img/eps/fig2.eps"
unset border
set key at -2, 1.5 font 'LiberationSerif, 23'
set key left top samplen 4.5
set xzeroaxis
set yzeroaxis
set x2zeroaxis
set y2zeroaxis
max = 1.5
min = -max
set xtics axis 0,.5,max in scale 0.5,0.25 mirror norotate autojustify offset 0.35 font 'LiberationSerif, 20
set ytics axis .5,.5,max in scale 0.5,0.25 mirror norotate autojustify font 'LiberationSerif, 20
set x2tics axis .5,.5,max in scale 0.5,0.25 mirror norotate autojustify font 'LiberationSerif, 20
set y2tics axis .5,.5,max in scale 0.5,0.25 mirror norotate autojustify font 'LiberationSerif, 20
set xrange [ min : max ]
set yrange [ min : max ]
set x2range [ max : min ]
set y2range [ max : min ]
set label "H_1" at 0, max center offset char 2, 0 font 'LiberationSerif, 23'
set label "H_2" at max+0.1, 0 center offset char -1, 1 font 'LiberationSerif, 23'
set label "H_3" at 0, min center offset char -2, 0 font 'LiberationSerif, 23'
set label "H_4" at min, 0 center offset char 0, 1 font 'LiberationSerif, 23'
set style line 1 linetype 1 pointtype 7 linewidth 3 linecolor black
set style line 2 linetype 2 pointtype 7 linewidth 3 linecolor black
plot 'data.csv' using 1:2 title "1" w lp ls 1 ,
'data.csv' using 3:4 title "2" w lp ls 2
Source: habr.com