Search code examples
gnuplotlinechart

Is it possible to have labels on y axis in gnuplot in a vertical line chart?


I have tried browsing tutorials and examples about Gnuplot, but none seem to cover problem I have at hand.

I made a mockup of a chart I would like to draw:

Desired plot

Data would be presented in this manner:

Item A  10  80
Item B  24  75
Item C  25  52
Item D  24  45
Item E  30  43
....

Number of rows would be higher but only two series'.

I am complete beginner when it comes to Gnuplot, but as Excel can't draw vertical line charts I thought that maybe Gnuplot could be made to but haven't been able to figure out how or if it even is possible at all.

Any pointers on direction I should take are appreciated.


Solution

  • This answer assumes that the columns of the data file are tab delimited.

    There are a couple of steps to achieve this:

    1. You need to swap x and y coordinates, e.g. use using 2:0 instead of using 0:2.
    2. The y-axis needs to be reversed: set yrange [] reverse.
    3. Use the first column as labels for the y-tics: using 2:0:yticlabels(1).
    4. Place key above the plot: set key above.

    All taken together:

    set key above
    set yrange [] reverse
    set datafile separator '\t'
    plot 'data.txt' using 2:0:yticlabels(1) with lines title 'Series A', \
         'data.txt' using 3:0               with lines title 'Series B'
    

    The result:

    Result of the above Gnuplot script