How to flip the axis of a plot under ruby?

52 views Asked by At

I wrote a ruby function to display the contents of a Daru dataframe df:

def plot_dataframe(df)
    test = df.plot type: :line, x: :value, y: :depth
    test.export_html(filename='test')
return
end

This outputs an html file named test.html.

How can I flip the y axis (ordinate) so that the depth starts at 0 and increases downwards?

I am looking for an equivalent to Python's invert_yaxis().


At @Serge de Gosson de Varennes' request, here is a MRE:

require 'json'
require 'daru'
require 'nyaplot'


df = Daru::DataFrame.new(
value: [1.2, 1.4, 1.1, 1.0, 1.0],
depth: [0, 1, 2, 3, 4] 
)

 

test = df.plot type: :line, x: :value, y: :depth, y_reverse: true
test.export_html(filename='MRE')

This outputs:

enter image description here

1

There are 1 answers

3
Serge de Gosson de Varennes On

You can do this in one of two ways:

def plot_dataframe(df)
    test = df.plot type: :line, x: :value, y: :depth, y_reverse: true
    test.export_html(filename='test')
return
end

or

def plot_dataframe(df)
    test = df.plot type: :line, x: :value, y: :depth, y_axis_scale: :reverse
    test.export_html(filename='test')
return
end