简体   繁体   中英

How to flip the axis of a plot under ruby?

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:

在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM