在子图 Python 中绘制对数比例

fre*_*rtz 4 python plotly

我的数据框中有 3 列。我已经将它们全部绘制成图表,下面的代码将它们并排放置在一个子图中。我想将第三个图表“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()
Run Code Online (Sandbox Code Playgroud)

Fla*_*ino 8

请参阅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()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明