shao
This commit is contained in:
parent
9eff845195
commit
39ace236f4
|
@ -0,0 +1,43 @@
|
|||
import plotly.express as px
|
||||
|
||||
fig = px.line(x=["a","b","c"], y=[1,3,2], title="sample figure")
|
||||
print(fig)
|
||||
fig.show()
|
||||
|
||||
# Figures As Dictionaries
|
||||
fig = dict({
|
||||
"data": [{"type": "bar",
|
||||
"x": [1, 2, 3],
|
||||
"y": [1, 3, 2]}],
|
||||
"layout": {"title": {"text": "A Figure Specified By Python Dictionary"}}
|
||||
})
|
||||
|
||||
# To display the figure defined by this dict, use the low-level plotly.io.show function
|
||||
import plotly.io as pio
|
||||
|
||||
pio.show(fig)
|
||||
|
||||
# Figures as Graph Objects
|
||||
import plotly.graph_objects as go
|
||||
|
||||
fig = go.Figure(
|
||||
data=[go.Bar(x=[1, 2, 3], y=[1, 3, 2])],
|
||||
layout=go.Layout(
|
||||
title=go.layout.Title(text="A Figure Specified By A Graph Object")
|
||||
)
|
||||
)
|
||||
|
||||
fig.show()
|
||||
# ou can also create a graph object figure from a dictionary representation by passing the dictionary to the go.Figure constructor.
|
||||
import plotly.graph_objects as go
|
||||
|
||||
dict_of_fig = dict({
|
||||
"data": [{"type": "bar",
|
||||
"x": [1, 2, 3],
|
||||
"y": [1, 3, 2]}],
|
||||
"layout": {"title": {"text": "A Figure Specified By A Graph Object With A Dictionary"}}
|
||||
})
|
||||
|
||||
fig = go.Figure(dict_of_fig)
|
||||
|
||||
fig.show()
|
|
@ -0,0 +1,10 @@
|
|||
import numpy as np
|
||||
import plotly.figure_factory as ff
|
||||
|
||||
x1,y1 = np.meshgrid(np.arange(0, 2, .2), np.arange(0, 2, .2))
|
||||
u1 = np.cos(x1)*y1
|
||||
v1 = np.sin(x1)*y1
|
||||
|
||||
fig = ff.create_quiver(x1, y1, u1, v1)
|
||||
|
||||
fig.show()
|
|
@ -0,0 +1,8 @@
|
|||
from plotly.subplots import make_subplots
|
||||
import plotly.graph_objects as go
|
||||
fig = make_subplots(rows=1, cols=2)
|
||||
|
||||
fig.add_trace(go.Scatter(y=[4, 2, 1], mode="lines"), row=1, col=1)
|
||||
fig.add_trace(go.Bar(y=[2, 1, 3]), row=1, col=2)
|
||||
|
||||
fig.show()
|
|
@ -0,0 +1,9 @@
|
|||
import plotly.express as px
|
||||
|
||||
df = px.data.iris()
|
||||
|
||||
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species", title="A Plotly Express Figure")
|
||||
# If you print the figure, you'll see that it's just a regular figure with data and layout
|
||||
# print(fig)
|
||||
|
||||
fig.show()
|
|
@ -0,0 +1,34 @@
|
|||
from dash import Dash, dcc, html, Input, Output
|
||||
import plotly.express as px
|
||||
import json
|
||||
|
||||
fig = px.line(
|
||||
x=["a","b","c"], y=[1,3,2], # replace with your own data source
|
||||
title="sample figure", height=325
|
||||
)
|
||||
|
||||
app = Dash(__name__)
|
||||
|
||||
app.layout = html.Div([
|
||||
html.H4('Displaying figure structure as JSON'),
|
||||
dcc.Graph(id="graph", figure=fig),
|
||||
dcc.Clipboard(target_id="structure"),
|
||||
html.Pre(
|
||||
id='structure',
|
||||
style={
|
||||
'border': 'thin lightgrey solid',
|
||||
'overflowY': 'scroll',
|
||||
'height': '275px'
|
||||
}
|
||||
),
|
||||
])
|
||||
|
||||
|
||||
@app.callback(
|
||||
Output("structure", "children"),
|
||||
Input("graph", "figure"))
|
||||
def display_structure(fig_json):
|
||||
return json.dumps(fig_json, indent=2)
|
||||
|
||||
|
||||
app.run_server(debug=True)
|
Loading…
Reference in New Issue