You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: How to make bubble charts in Python with Plotly.
15
26
display_as: basic
@@ -24,59 +35,60 @@ jupyter:
24
35
redirect_from: python/bubble-charts-tutorial/
25
36
thumbnail: thumbnail/bubble.jpg
26
37
title: Bubble Charts | plotly
38
+
v4upgrade: true
27
39
---
28
40
29
-
#### New to Plotly?
30
-
Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/).
31
-
<br>You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/#start-plotting-online).
32
-
<br>We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!
33
-
#### Version Check
34
-
Plotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version.
41
+
## Bubble chart with plotly.express
42
+
43
+
A [bubble chart](https://en.wikipedia.org/wiki/Bubble_chart) is a scatter plot in which a third dimension of the data is shown through the size of markers. For other types of scatter plot, see the [line and scatter page](https://plot.ly/python/line-and-scatter/).
44
+
45
+
We first show a bubble chart example using plotly express. Plotly express functions take as argument a tidy [pandas DataFrame](https://pandas.pydata.org/pandas-docs/stable/getting_started/10min.html). The size of markers is set from the dataframe column given as the `size` parameter.
When data are not available as tidy dataframes, it is also possible to use the more generic `go.Scatter` from `plotly.graph_objects`, and define the size of markers to create a bubble chart. All of the available options are described in the scatter section of the reference page: https://plot.ly/python/reference#scatter.
60
+
41
61
### Simple Bubble Chart
42
62
43
63
```python
44
-
import plotly.plotly as py
45
-
import plotly.graph_objs as go
64
+
import plotly.graph_objects as go
46
65
47
-
trace0 = go.Scatter(
48
-
x=[1, 2, 3, 4],
49
-
y=[10, 11, 12, 13],
66
+
fig = go.Figure(data=[go.Scatter(
67
+
x=[1, 2, 3, 4], y=[10, 11, 12, 13],
50
68
mode='markers',
51
-
marker=dict(
52
-
size=[40, 60, 80, 100],
53
-
)
54
-
)
55
-
56
-
data = [trace0]
57
-
py.iplot(data, filename='bubblechart-size')
69
+
marker_size=[40, 60, 80, 100])
70
+
])
71
+
72
+
fig.show()
58
73
```
59
74
60
75
### Setting Marker Size and Color
61
76
62
77
```python
63
-
import plotly.plotly as py
64
-
import plotly.graph_objs as go
78
+
import plotly.graph_objects as go
65
79
66
-
trace0 = go.Scatter(
67
-
x=[1, 2, 3, 4],
68
-
y=[10, 11, 12, 13],
80
+
fig = go.Figure(data=[go.Scatter(
81
+
x=[1, 2, 3, 4], y=[10, 11, 12, 13],
69
82
mode='markers',
70
83
marker=dict(
71
84
color=['rgb(93, 164, 214)', 'rgb(255, 144, 14)',
72
85
'rgb(44, 160, 101)', 'rgb(255, 65, 54)'],
73
86
opacity=[1, 0.8, 0.6, 0.4],
74
87
size=[40, 60, 80, 100],
75
88
)
76
-
)
89
+
)])
77
90
78
-
data = [trace0]
79
-
py.iplot(data, filename='bubblechart-color')
91
+
fig.show()
80
92
```
81
93
82
94
### Scaling the Size of Bubble Charts
@@ -86,11 +98,10 @@ Note that setting 'sizeref' to a value greater than 1, decreases the rendered ma
86
98
Additionally, we recommend setting the sizemode attribute: https://plot.ly/python/reference/#scatter-marker-sizemode to area.
0 commit comments