0

I have a nice gnuplot graphic in which I want to change the labeling in the key. The problem that I have is related to the filledcurves option. To make things easier, I attached the image. As one can see, the key labeling is 2 - 1 - 3 while I would like to have 1 - 2 - 3 while keeping the same filledcurves pattern. Sure, simply changing the order of my plot, will give me 1 - 2 - 3 but respectively the pattern of the filling changes too and I want to avoid this. I was trying to hack it somehow by using the NaN possibilities in gnuplot (https://stackoverflow.com/questions/10614654/gnuplot-legend-order) but the problem here is that the filling is different. While checking the gnuplot documentation (http://www.bersch.net/gnuplot-doc/filledcurves.html) I realized that there is no option to fix the pattern but I guess there should be some way. For testing, I attached the gnuplot script.

enter image description here

#!/bin/gnuplot
#------------------------------------------------------------------------------

set grid
set key right top
set xrange [20:220]

set style line 20 lw 2 lc rgb 'black'
set border linestyle 20
set style line 1 lw 2.0 lc rgb 'dark-gray'
set style line 2 lw 2.0 lc rgb '#202020'
set style line 3 lw 2.0 lc rgb 'gray'
set style fill transparent pattern 2


#------------------------------------------------------------------------------
A=-1.74959e-14
B=-1.87199e-12
C=1.87756e-9
DeltaBDP=0.45e-9

OffsetBP=0.05e-9
DeltaBP=0.8e-9

OffsetB=0.7e-9
DeltaB=0.8e-9

# 
f(x)=A*x**2+B*x+C
g(x)=f(x)+DeltaBDP

# Beta P
h(x)=f(x)+OffsetBP
i(x)=h(x)+DeltaBP

# Beta
j(x)=h(x)+OffsetB
k(x)=j(x)+DeltaB

#------------------------------------------------------------------------------

set terminal epslatex
set output 'tex/foobar.tex'
plot \
'+' using 1:(j($1)*1e9):(k($1)*1e9) with filledcurves closed lc rgb 'dark-gray' t '2' , \
'+' using 1:(f($1)*1e9):(g($1)*1e9) with filledcurves closed lc rgb 'dark-gray' t '1', \
'+' using 1:(h($1)*1e9):(i($1)*1e9) with filledcurves closed lc rgb '#202020' t '3', \
f(x)*1e9 w l ls 1 t '', \
g(x)*1e9 w l ls 1 t '', \
h(x)*1e9 w l ls 2 t '', \
i(x)*1e9 w l ls 2 t '', \
j(x)*1e9 w l ls 3 t '', \
k(x)*1e9 w l ls 3 t ''


#------------------------------------------------------------------------------
1

I can't test it now, but maybe the second answer on this page does work: https://stackoverflow.com/questions/6290504/reordering-gnuplot

  • Thanks for the hint. I did similar things but the problem is, that the filledcurves style is changing. So if I have plot 1 - 3 without title and I add empty plots 4 - 6, then the filling pattern is now the same as in 1 - 3. Unfortunately, I have no glue how to change the filling pattern namely the filledcurves style. – Tobi Feb 3 '18 at 12:09
1

If someone has the same problem, the solution is simple (as always). After searching for the keyword pattern style fill it was obvious how to deal with that. First, as I already did and @ksyrium also mentioned is to unset the titles in the plots. Subsequent, adding NaN plots while choosing the pattern by using fill pattern <int>. Doing so, the ordering in the NaNplots can be changed as one likes to have it.

plot \
'+' using 1:(j($1)*1e9):(k($1)*1e9) with filledcurves closed lc rgb 'dark-gray' t '1real', \
'+' using 1:(f($1)*1e9):(g($1)*1e9) with filledcurves closed lc rgb 'dark-gray' t '2real', \
'+' using 1:(h($1)*1e9):(i($1)*1e9) with filledcurves closed lc rgb '#202020' t '3real', \
f(x)*1e9 w l ls 1 t '', \
g(x)*1e9 w l ls 1 t '', \
h(x)*1e9 w l ls 2 t '', \
i(x)*1e9 w l ls 2 t '', \
j(x)*1e9 w l ls 3 t '', \
k(x)*1e9 w l ls 3 t '', \
NaN with filledcurves closed fill pattern 2 lc rgb 'dark-gray' t '1', \
NaN with filledcurves closed fill pattern 3 lc rgb 'dark-gray' t '2', \
NaN with filledcurves closed fill pattern 4 lc rgb '#202020' t '3'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.