'python-plotly-multiple y-axis: How to turn off grid on both subplots?
I am new to python and am enjoying the debugging help that stack overflow community provides.
In the following code I am able to remove y-axis grid for top subplot but unable to remove grid from the bottom subplot (row=2).
What am I doing wrong? I appreciate your help. -VB
import plotly.graph_objects as go
from plotly.subplots import make_subplots
fig1 = make_subplots(rows=2,
specs=[[{"secondary_y": True}],
[{"secondary_y": True}]])
x1_shorter = [1, 2, 3, 4, 5]
y1_shorter = [1, 2, 1, 2, 1]
y2_shorter = [202, 98, 202, 98, 202]
x1_longer = [1, 2, 3, 4, 5, 6, 7, 8, 9]
y1_longer = [1, 2, 1, 2, 1, 2, 1, 2, 1]
y2_longer = [202, 98, 202, 98, 202, 98, 202, 98, 202]
fig1.add_trace(
go.Scatter(x=x1_shorter, y=y1_shorter, name="yaxis data"),
row=1, col=1, secondary_y=False)
fig1.add_trace(
go.Scatter(x=x1_shorter, y=y2_shorter, name="yaxis2 data"),
row=1, col=1, secondary_y=True)
fig1.add_trace(
go.Scatter(x=x1_longer, y=y1_longer, name="yaxis5 data"),
row=2, col=1, secondary_y=False)
fig1.add_trace(
go.Scatter(x=x1_longer, y=y2_longer, name="yaxis6 data"),
row=2, col=1, secondary_y=True)
fig1['layout']['yaxis1']['showgrid'] = False
fig1['layout']['yaxis2']['showgrid'] = False
fig1.show()
Solution 1:[1]
I found a solution for this here: https://stackoverflow.com/a/42535950/18460516
You can remove the horizontal gridlines using update_yaxes():
fig1.update_yaxes(secondary_y=False, showgrid=False)
fig1.update_yaxes(secondary_y=True, showgrid=False)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Alexander Heidenreich |