Gert Gottschalk
Gert Gottschalk

Reputation: 1716

gnuplot absolutely no y-markings at all and x-axis to front

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: enter image description here

Upvotes: 1

Views: 4294

Answers (2)

theozh
theozh

Reputation: 25684

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:

enter image description here

Upvotes: 3

Ethan
Ethan

Reputation: 15093

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"

enter image description here

Upvotes: 0

Related Questions