Dark Templar
Dark Templar

Reputation: 1295

Group bar chart graph with two different y-axis scales in gnuplot?

Good day,

I need to create a group bar chart graph with different scales.

Consider following data example:

Metric A B
Group1 10 1500
Group2 20 4000

I am using this answer and this code:

reset
set style histogram cluster gap 1
set style data histograms
set style fill solid 1.00 border
set yrange [0:]
set ytics nomirror
set y2range [0:]
set y2tics

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

The code above creates this plot:

enter image description here

However, what I need is:

  1. Left Y scale to be [0:20]
  2. All numbers from A to be plotted according to left Y scale
  3. All numbers from B to be plotted according to right Y scale
  4. If possible, to put labels on both left and right Y scale.
  5. If possible, to have only one pair of A and B in the legend.

This way, the Violet color Bars will be much higher, and dependent only on column A number range.

Thank you very much!

Upvotes: 0

Views: 1907

Answers (1)

Raphael Roth
Raphael Roth

Reputation: 27373

try using 2 axis using y2:

set ytics nomirror
set y2tics
set yrange [0:20]
set y2range [0:] 
set key right

label = "MyLabel"
set ylabel label
set y2label label

set style data histograms
plot 'histplot.dat' using 2 ti col axis x1y1, '' u 3:xticlabels(1) ti col axis x1y2

Upvotes: 2

Related Questions