4

I could not find a solution to the following issue I am facing. All SO questions on multi-axis talk about line plots, but I am looking for histograms.

The y-range for the bars are different, so one set of bars are not really seen because of the scale. Here is the data:


Metric A B
M1 0.613416301 0.543734744 
M2 0.000195961 0.000100190

Here is the MWE:


reset
set term postscript eps size 5.5,4.5 enhanced color font 'Arial-Bold' 25
set out 'histplot.eps'
set key right 
set style histogram cluster gap 2 
set style data histograms
set style fill pattern 1.00 border
set y2range [0.0001:0.0002]
plot 'histplot.dat' using 2 ti col, '' u 3:xticlabels(1) ti col
quit

This is the sample output (one set of bars over M2 is not seen): compare metrics

What I prefer is to have a second y-axis (to the right side of the plot) with a range appropriate to the second row of my data file. Is this possible? Any help is greatly appreciated.

4
  • Just to clarify: You do not want a broken axis, logarithmic scaling or similar? Commented Jan 4, 2015 at 11:58
  • @Wrzlprmft : Yes, I do not want logarithmic scaling. Sorry, did not understand the broken axis term. Commented Jan 5, 2015 at 19:24
  • Here is an example for a broken axis. Commented Jan 5, 2015 at 19:26
  • @Wrzlprmft: Thank you. I prefer an unbroken axis. Commented Jan 5, 2015 at 19:33

1 Answer 1

5

Normally you can plot severyl histograms beneath each other using newhistogram. However, it seems like this is buggy when using patterns as fillstyle:

reset
set style histogram cluster gap 1
set style data histograms
set style fill pattern 1.00 border

set yrange [0:*]
set ytics nomirror
set y2range [0:*]
set y2tics

set key right autotitle columnheader
plot 'histplot.dat' u 2 every ::::0, '' u 3:xtic(1) every ::::0,\
     newhistogram lt 1 at 1,\
     'histplot.dat' u 2 every ::1::1 axes x1y2, '' u 3:xtic(1) every ::1::1 axes x1y2

enter image description here

Alternatively you can use multiplot and plot the two histograms directly beneath each other:

reset
set style histogram cluster gap 1
set style data histograms
set style fill pattern 1.00 border

set yrange [0:*]
set ytics nomirror
set multiplot layout 1,2
set rmargin at screen 0.5
set lmargin 9
unset key
plot 'histplot.dat' using 2 every ::::0 ti col, '' u 3:xticlabels(1) every ::::0 ti col

set rmargin 9
set lmargin at screen 0.5
unset ytics
set y2range [0:*]
set y2tics
set key right
plot '' using 2 every ::1::1 axes x1y2 ti col, '' u 3:xtic(1) every ::1::1 axes x1y2 ti col
unset multiplot

enter image description here

If you don't want the separating black line, you can use set border 7 for the first and set border 13 for the second plot.

Sign up to request clarification or add additional context in comments.

1 Comment

This is great! Thank you v.much. Your answers to a lot of gnuplot questions are really useful. Thanks for that too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.