簡體   English   中英

Plotly 子圖中的對數比例 Python

[英]Plotly Log Scale in Subplot Python

我的 dataframe 中有 3 列。 我將它們全部繪制在 plotly 中,下面的代碼將它們並排放置在子圖中。 我想將第三個圖表“c”更改為對數刻度。 這可能嗎?

fig = make_subplots(rows=1, cols=3)
fig.add_trace(
    go.Scatter(x = df.index,y = df['a'],mode = 'lines+markers',name = 'Daily')

fig.add_trace(
    go.Scatter(x = df.index,y = df['b'],mode = 'lines+markers',name = 'Total'    )

fig.add_trace(
    go.Scatter(x = df.index,y = df['c'],mode = 'lines+markers',name = 'Total'
)


fig.layout()
fig.update_layout(height=600, width=800, title_text="Subplots")
fig.show()

請參閱Plotly 文檔中的“自定義子圖軸”部分。 我在下面為 2 個子圖提供了一個示例,但無論子圖的數量如何,邏輯都是相同的。

import plotly.graph_objects as go
from plotly.subplots import make_subplots

fig = make_subplots(rows=1, cols=2, subplot_titles=("Default Scale", "Logarithmic Scale"))

# subplot in default scale
fig.add_trace(go.Scatter(x=[0.1, 0.2, 0.3, 0.4, 0.5], y=[1.105, 1.221, 1.35, 1.492, 1.649]), row=1, col=1)
fig.update_xaxes(title_text="x-axis in default scale", row=1, col=1)
fig.update_yaxes(title_text="y-axis in default scale", row=1, col=1)

# subplot in logarithmic scale
fig.add_trace(go.Scatter(x=[0.1, 0.2, 0.3, 0.4, 0.5], y=[1.105, 1.221, 1.35, 1.492, 1.649]), row=1, col=2)
fig.update_xaxes(title_text="x-axis in logarithmic scale", type="log", row=1, col=2)
fig.update_yaxes(title_text="y-axis in logarithmic scale", type="log", row=1, col=2)

fig.update_layout(showlegend=False)

fig.show()

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM