[英]Remove left and right labels and paint values 1 by 1 in x-axis with Plotly that use facet_row or instead use make_subplots in Python
[英]How to remove vertical line at x-axis and add labels to plotly subplots?
我一直在嘗試使用plotly庫創建子圖。 我已經完成了大部分工作,但想知道如何添加以下內容:
到目前為止,這是我的代碼:
import numpy as np
import plotly
import plotly.offline as py
import plotly.plotly as pyp
import plotly.graph_objs as go
import plotly.figure_factory as ff
import plotly.tools as tls
from plotly.offline import plot, iplot, init_notebook_mode
init_notebook_mode(connected=False)
np.random.seed(42)
data = np.random.binomial(10, 0.3, 10000)
x, y = np.sort(data), np.arange(1, len(data)+1) / len(data)
idx = np.abs(y-0.5).argmin()
z = x[idx]
hist0 = go.Histogram(x = data,name='Histogram')
sc1 = go.Scatter(x=x,y=y,mode = 'markers',name = 'Empirical CDF')
sc2 = go.Scatter(x=x,y=[0.5]*len(x),mode = 'lines',name = 'y=0.5 (central tendency)')
sc3 = go.Scatter(x=[z]*1000,y=np.linspace(0,1,1000),mode = 'lines',name = 'x={:.2f}'.format(z))
fig = plotly.tools.make_subplots(rows=1, cols=2, shared_xaxes=True,
subplot_titles=('Histogram','Empirical CDF'))
fig.append_trace(hist0, 1, 1)
fig.append_trace(sc1, 1, 2)
fig.append_trace(sc2, 1, 2)
fig.append_trace(sc3, 1, 2)
fig['layout'].update(height=400, width=800, title='')
iplot(fig)
假設您正在使用plotly
版本4:
fig.update_xaxes(row=1, col=2, zeroline=False)
刪除垂直x = 0線 fig.update_xaxes(row=1, col=1, title="title")
標記軸(用yaxes
代替xaxes
並為row
/ col
設置適當的標題 如果您使用的是版本3:
fig.layout.xaxis<n>.zeroline=False
從任何x軸上刪除零線(適當設置n
,在這種情況下可能為2
) fig.layout.<dim>axis<n>.title="title"
設置任何坐標軸的fig.layout.<dim>axis<n>.title="title"
(適當地設置dim
和n
,例如yaxis1
等)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.