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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With