简体   繁体   中英

Plotly Log Scale in Subplot Python

I have a 3 columns in my dataframe. I have charted them all in plotly, and the below code puts them side by side in a subplot. I would like to change the third chart 'c' to have a logarithmic scale. Is this possible?

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()

See the section on "Customizing Subplot Axes" in the Plotly documentation . I included an example below for 2 subplots, but the logic is the same regardless of the number of subplots.

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()

在此处输入图像描述

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