【发布时间】:2019-07-04 06:46:07
【问题描述】:
我在破折号中设置了一个dcc.Graph() 对象,并将该图设置为我在plotly 中创建的散点图。
该图完全按照我在plotly 中的方式显示其所有数据,但是当我运行本地服务器并查看破折号中的图时,除了轴和刻度标签外,所有内容都是空白的。
我尝试了以下方法 - 编辑布局中的宽度和高度 - 创建了一个只有图形对象的仪表板服务器 - 单独运行图表 - 查看 plotly 主页上的图形表示
其他图表的数据有效并显示在同一个破折号中,但不是这个。
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
from sklearn import linear_model
def create_tile_scatter_plot_figure():
def data_to_plotly(x):
k = []
for i in range(0, len(x)):
k.append(x[i][0])
return k
tiles = ['ALAÏA Vienne Laser-Cut Leather Tote',
'AZZEDINE ALAÏA LASER-CUT KNITTED DRESS',
'NEOPRENE SNEAKERS',
'GRIP JACKET BLACK',
'ORBIT PANT BLACK',
'BLACK SHELL, MULTI FOX FUR',
'LEATHER JACKET', 'LAUREN RALPH LAUREN Turtleneck Sweater',
'Edwart Paris',
'SG VARSITY POM BEANIE DARK BLUE',
'Pro Longwear Foundation',
'CHOCOLATE EYE PALETTE',
'ALAÏA Laser-Cut Ankle Boots',
'Mac 12 Lash',
'Bobby Brown BUFF A Beige Pink Lipgloss',
'ALAÏA Bracelet Leather Bucket Bag',
'Bar 8 Mandarin Oriental Hotel',
'Mandarin Hotel Paris', 'Grand Palais Paris']
x_data = np.array([i + 1 for i in range(len(tiles))]).reshape(-1, 1)
y_data = np.array([383, 367, 320, 318, 327, 420, 377, 303, 283, 302, 264, 257, 296,
317, 335, 302, 292, 297, 264]).reshape(-1, 1)
tickvals = [i + 1 for i in range(len(tiles))]
regr = linear_model.LinearRegression().fit(x_data, y_data)
p1 = go.Scatter(x=data_to_plotly(x_data),
y=y_data,
mode='markers',
marker=dict(color='black')
)
p2 = go.Scatter(x=data_to_plotly(x_data),
y=regr.predict(x_data),
mode='lines',
line=dict(color='blue', width=3)
)
layout = go.Layout(title='Engagement by Tile',
paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)',
width=1300,
height=800,
xaxis=dict(ticks='',
ticktext=tiles,
tickvals=tickvals,
showgrid=False,
showline=True,
showticklabels=True,
automargin=False,
range=[0, len(tiles)+1]),
yaxis=dict(ticks='',
showgrid=False,
showline=True,
showticklabels=False,
automargin=True),
showlegend=False,
hovermode='closest')
return go.Figure(data=[p1, p2], layout=layout)
app = dash.Dash(__name__)
app.layout = html.Div(id='main-container', children=[
dcc.Graph(id='scatter-regression', figure=create_tile_scatter_plot_figure())]),
])
if __name__ == '__main__':
app.run_server(debug=True)
我希望数据以破折号出现在图表上,但我看不到它。
【问题讨论】:
标签: python plotly-dash plotly-python