gpt4 book ai didi

python - 在子图 Python 中绘制对数比例

转载 作者:行者123 更新时间:2023-12-03 20:08:05 27 4
gpt4 key购买 nike

我的数据框中有 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()

最佳答案

请参阅 Plotly documentation 中有关“自定义子图轴”的部分.我在下面包含了 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()
enter image description here

关于python - 在子图 Python 中绘制对数比例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61041707/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com