Getting to know the data attribute
First, we start by adding a scatter plot using a very small and simple dataset. Later in the chapter, we will use our poverty dataset to create other plots. Once you have created your Figure object and assigned it to a variable, you have access to a large number of convenient methods for manipulating that object. The methods related to adding data traces all start with add_, followed by the type of chart we are adding, for example, add_scatter or add_bar.
Let's go through the full process of creating a scatter plot:
- Import the
graph_objectsmodule:import plotly.graph_objects as go
- Create an instance of a
Figureobject and assign it to a variable:fig = go.Figure()
- Add a scatter trace. The minimum parameters required for this type of chart are two arrays for the
xandyvalues. These can be provided as lists, tuples, NumPy arrays, or pandasSeries:fig.add_scatter(x=[1, 2, 3], y=[4, 2, 3])
- Display the resulting figure. You...