6. Using Dictionaries to make Figures#
# Import the module Plotly Io as pio
import plotly.io as pio
# Create a dictionary to specify both the data and the layout of your figure
fig = dict({
"data": [{"type": "scatter",
"x": [1, 2, 3, 4,5],
"y": [1, 4, 9, 16, 25],
"marker": {'symbol': 'circle'}
}],
"layout": {"title": {"text": "A Figure Specified By a Python Dictionary"}}
})
# Display your figure
pio.show(fig)
# Create a dictionary to specify both the data and the layout of your figure
import numpy as np
x = np.linspace(-10, 10, 300)
y = np.sin(x)
fig = dict({
"data": [{"type": "scatter",
"x": x,
"y": y,
"marker": {'symbol': 'circle'},
"line_color" : 'red',
}],
"layout": {"title": {"text": "A More Interesting Figure Specified By a Python Dictionary"}}
})
# Display your figure
pio.show(fig)
# Create a dictionary to specify both the data and the layout of your figure
fig = dict({
"data": [{"type": "bar",
"x": [1, 2, 3],
"y": [10, 30, 15]}],
"layout": {"title": {"text": "A Bar Chart Specified By a Python Dictionary"}}
})
# Display your figure
pio.show(fig)