Python 在plotly中更新特定子地块轴
设置:Python 在plotly中更新特定子地块轴,python,python-3.x,plotly,plotly-python,Python,Python 3.x,Plotly,Plotly Python,设置: import numpy as np from plotly.subplots import make_subplots from math import exp fig = make_subplots(2, 1) x = np.linspace(0, 10, 1000) y = np.array(list(map(lambda x: 1 / (1 + exp(-0.1 * x + 5)), x))) fig.add_trace( go.Scatter( x=
import numpy as np
from plotly.subplots import make_subplots
from math import exp
fig = make_subplots(2, 1)
x = np.linspace(0, 10, 1000)
y = np.array(list(map(lambda x: 1 / (1 + exp(-0.1 * x + 5)), x)))
fig.add_trace(
go.Scatter(
x=x,
y=y,
name=f'\N{Greek Small Letter Sigma}(x)',
showlegend=True
),
row=1,
col=1
)
fig.update_xaxes(title_text='x')
x = np.where(np.random.randint(0, 2, 100)==1)[0]
fig.add_trace(
go.Scatter(
x=x,
y=np.zeros_like(x),
name=f'Plot 2',
mode='markers',
marker=dict(
symbol='circle-open',
color='green',
size=5
),
showlegend=True
),
row=2,
col=1
)
fig.update_xaxes(title_text='active users')
fig.show()
import numpy as np
from plotly.subplots import make_subplots
from math import exp
fig = make_subplots(2, 1)
x = np.linspace(0, 10, 1000)
y = np.array(list(map(lambda x: 1 / (1 + exp(-0.1 * x + 5)), x)))
fig.add_trace(
go.Scatter(
x=x,
y=y,
name=f'\N{Greek Small Letter Sigma}(x)',
showlegend=True
),
row=1,
col=1
)
fig['layout']['xaxis'].update(title_text='x')
x = np.where(np.random.randint(0, 2, 100)==1)[0]
fig.add_trace(
go.Scatter(
x=x,
y=np.zeros_like(x),
name=f'Plot 2',
mode='markers',
marker=dict(
symbol='circle-open',
color='green',
size=5
),
showlegend=True
),
row=2,
col=1
)
fig['layout']['xaxis2'].update(title_text='active users')
fig.show()
- 我正尝试使用
库绘制子地块,但不知道如何引用特定子地块的轴来更改其名称(或其他属性)plotly
- 在
中,我展示了一个简单的示例,其中我使用code 1
在另一个图的顶部添加了两个图plotly.subplot.make_subplot
import numpy as np
from plotly.subplots import make_subplots
from math import exp
fig = make_subplots(2, 1)
x = np.linspace(0, 10, 1000)
y = np.array(list(map(lambda x: 1 / (1 + exp(-0.1 * x + 5)), x)))
fig.add_trace(
go.Scatter(
x=x,
y=y,
name=f'\N{Greek Small Letter Sigma}(x)',
showlegend=True
),
row=1,
col=1
)
x = np.where(np.random.randint(0, 2, 100)==1)[0]
fig.add_trace(
go.Scatter(
x=x,
y=np.zeros_like(x),
name=f'Plot 2',
mode='markers',
marker=dict(
symbol='circle-open',
color='green',
size=5
),
showlegend=True
),
row=2,
col=1
)
fig.show()
我所尝试的
我曾尝试在每次添加跟踪后使用fig.update_xaxes()
,但它会弄乱绘图,并且不会产生所需的输出,如code 2
中所示
代码2:
import numpy as np
from plotly.subplots import make_subplots
from math import exp
fig = make_subplots(2, 1)
x = np.linspace(0, 10, 1000)
y = np.array(list(map(lambda x: 1 / (1 + exp(-0.1 * x + 5)), x)))
fig.add_trace(
go.Scatter(
x=x,
y=y,
name=f'\N{Greek Small Letter Sigma}(x)',
showlegend=True
),
row=1,
col=1
)
fig.update_xaxes(title_text='x')
x = np.where(np.random.randint(0, 2, 100)==1)[0]
fig.add_trace(
go.Scatter(
x=x,
y=np.zeros_like(x),
name=f'Plot 2',
mode='markers',
marker=dict(
symbol='circle-open',
color='green',
size=5
),
showlegend=True
),
row=2,
col=1
)
fig.update_xaxes(title_text='active users')
fig.show()
import numpy as np
from plotly.subplots import make_subplots
from math import exp
fig = make_subplots(2, 1)
x = np.linspace(0, 10, 1000)
y = np.array(list(map(lambda x: 1 / (1 + exp(-0.1 * x + 5)), x)))
fig.add_trace(
go.Scatter(
x=x,
y=y,
name=f'\N{Greek Small Letter Sigma}(x)',
showlegend=True
),
row=1,
col=1
)
fig['layout']['xaxis'].update(title_text='x')
x = np.where(np.random.randint(0, 2, 100)==1)[0]
fig.add_trace(
go.Scatter(
x=x,
y=np.zeros_like(x),
name=f'Plot 2',
mode='markers',
marker=dict(
symbol='circle-open',
color='green',
size=5
),
showlegend=True
),
row=2,
col=1
)
fig['layout']['xaxis2'].update(title_text='active users')
fig.show()
这会导致(注意顶部打印的活动用户
):
我的问题:
import numpy as np
from plotly.subplots import make_subplots
from math import exp
fig = make_subplots(2, 1)
x = np.linspace(0, 10, 1000)
y = np.array(list(map(lambda x: 1 / (1 + exp(-0.1 * x + 5)), x)))
fig.add_trace(
go.Scatter(
x=x,
y=y,
name=f'\N{Greek Small Letter Sigma}(x)',
showlegend=True
),
row=1,
col=1
)
fig.update_xaxes(title_text='x')
x = np.where(np.random.randint(0, 2, 100)==1)[0]
fig.add_trace(
go.Scatter(
x=x,
y=np.zeros_like(x),
name=f'Plot 2',
mode='markers',
marker=dict(
symbol='circle-open',
color='green',
size=5
),
showlegend=True
),
row=2,
col=1
)
fig.update_xaxes(title_text='active users')
fig.show()
import numpy as np
from plotly.subplots import make_subplots
from math import exp
fig = make_subplots(2, 1)
x = np.linspace(0, 10, 1000)
y = np.array(list(map(lambda x: 1 / (1 + exp(-0.1 * x + 5)), x)))
fig.add_trace(
go.Scatter(
x=x,
y=y,
name=f'\N{Greek Small Letter Sigma}(x)',
showlegend=True
),
row=1,
col=1
)
fig['layout']['xaxis'].update(title_text='x')
x = np.where(np.random.randint(0, 2, 100)==1)[0]
fig.add_trace(
go.Scatter(
x=x,
y=np.zeros_like(x),
name=f'Plot 2',
mode='markers',
marker=dict(
symbol='circle-open',
color='green',
size=5
),
showlegend=True
),
row=2,
col=1
)
fig['layout']['xaxis2'].update(title_text='active users')
fig.show()
x
分配给顶部打印x轴,将活动用户
标签分配给底部打印的x轴行=1
位置上的绘图的xaxis
,col=1
和行=2
位置上的绘图的xaxis1
来解决这个问题。完整的解决方案在代码1
中
代码1:
import numpy as np
from plotly.subplots import make_subplots
from math import exp
fig = make_subplots(2, 1)
x = np.linspace(0, 10, 1000)
y = np.array(list(map(lambda x: 1 / (1 + exp(-0.1 * x + 5)), x)))
fig.add_trace(
go.Scatter(
x=x,
y=y,
name=f'\N{Greek Small Letter Sigma}(x)',
showlegend=True
),
row=1,
col=1
)
fig.update_xaxes(title_text='x')
x = np.where(np.random.randint(0, 2, 100)==1)[0]
fig.add_trace(
go.Scatter(
x=x,
y=np.zeros_like(x),
name=f'Plot 2',
mode='markers',
marker=dict(
symbol='circle-open',
color='green',
size=5
),
showlegend=True
),
row=2,
col=1
)
fig.update_xaxes(title_text='active users')
fig.show()
import numpy as np
from plotly.subplots import make_subplots
from math import exp
fig = make_subplots(2, 1)
x = np.linspace(0, 10, 1000)
y = np.array(list(map(lambda x: 1 / (1 + exp(-0.1 * x + 5)), x)))
fig.add_trace(
go.Scatter(
x=x,
y=y,
name=f'\N{Greek Small Letter Sigma}(x)',
showlegend=True
),
row=1,
col=1
)
fig['layout']['xaxis'].update(title_text='x')
x = np.where(np.random.randint(0, 2, 100)==1)[0]
fig.add_trace(
go.Scatter(
x=x,
y=np.zeros_like(x),
name=f'Plot 2',
mode='markers',
marker=dict(
symbol='circle-open',
color='green',
size=5
),
showlegend=True
),
row=2,
col=1
)
fig['layout']['xaxis2'].update(title_text='active users')
fig.show()
干杯。
fig.layout
比fig['layout']
稍微安全一些。