1. 概览
2. 安装
import plotly.graph_objects as go
fig = go.Figure(data=go.Bar(y=[2, 3, 1]))
# you can also use `fig.show()`
fig.write_html("first_figure.html", auto_open=True)
3. 在Dash中使用Plotly
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objects as go
from dash.dependencies import Input, Output
app = dash.Dash(__name__)
app.layout = html.Div([
html.P("Color:"),
dcc.Dropdown(
id="dropdown",
options=[
{"label": x, "value": x}
for x in ["Gold", "MediumTurquoise", "LightGreen"]
],
value="Gold",
clearable=False
),
dcc.Graph(id="graph")
])
@app.callback(
Output("graph", "figure"),
[Input("dropdown", "value")])
def display_color(color):
fig = go.Figure(data=go.Bar(y=[2, 3, 1], marker_color=color))
return fig
app.run_server(debug=True)
clearable
如果设置为 True,则在下拉框中会出现一个 x 清除选项
4. Jupyter Notebook支持
import plotly.graph_objects as go
fig = go.Figure(data=go.Bar(y=[2, 3, 1]))
fig.show()
💡 你也可以直接使用
FigureWidget
对象,改写上面语句为fig = go.FigureWidget(data=go.Bar(y=[2, 3, 1]))
,显示的页面效果是一样的。
5. JupyterLab支持
6. 静态图片导出
6.1 Kaleido
6.2 Orca
7. Geo地图扩展支持
8. Chart Studio支持
9. Dash是什么?
import dash
import plotly.graph_objects as go
import dash_core_components as dcc
import dash_html_components as html
fig = go.Figure()
app = dash.Dash()
app.layout = html.Div([
dcc.Graph(figure=fig)
])
app.run_server(debug=True, use_reloader=False)