到目前為止,我已經花了幾個小時來完成 plotnine 中的軸縮放。到目前為止我發現的一切都不起作用。
是資料,還是定義圖形的代碼,希望你們中的任何人都能看到哪里出了問題。
資料看起來像:

資料型別有:
concat object
direction object
date_trunc timedelta64[ns]
comment object
timestamp datetime64[ns]
dtype: object
以下代碼按預期創建圖形:
ch_time_plot = (p9.ggplot(data= ch_time,
mapping= p9.aes(x= 'timestamp',
y= 'date_trunc',
color= 'direction'))
p9.geom_line()
p9.theme(axis_text_x= p9.element_text(rotation=90))
)
# ch_time_plot = p9.ylim(0,5)
# => TypeError: Discrete value supplied to continuous scale
# ch_time_plot = p9.expand_limits(y=0)
# => AttributeError: 'int' object has no attribute 'value'
# ch_time_plot = p9.scale_y_continuous(limits = (1, 10))
# => TypeError: Discrete value supplied to continuous scale
ch_time_plot
我想要實作的是始終顯示 y 軸 (0) 的原點。一旦我注釋掉代碼中顯示的其中一行(應該這樣做),我就會收到一條錯誤訊息,不再有圖表。
我的代碼有什么問題?
uj5u.com熱心網友回復:
由于使用的資料型別,上例中的縮放不起作用。
只要在 y 軸上timedelta64[ns]使用縮放就不起作用。
經過以下轉換:
ch_time['change_time']= ch_time['date_trunc'] / np.timedelta64(1, 's')
該圖可以正確縮放:
ch_time_plot = (p9.ggplot(data= ch_time,
mapping= p9.aes(x= 'timestamp',
y= 'change_time',
color= 'direction'))
p9.geom_line()
p9.theme(axis_text_x= p9.element_text(rotation=90))
p9.scale_y_continuous(limits=(0, 6))
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/328495.html
上一篇:與patchwork結合時,將geom_point資料與geom_col資料對齊
下一篇:設定網格列始終為100%
