Skip to content

Commit 0bc7ba5

Browse files
PR feedback
1 parent 5430490 commit 0bc7ba5

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
77
### Added
88

99
- `plotly` now provides a Plotly Express-backed Pandas-compatible plotting backend, which can be activated via `pandas.options.plotting.backend = "plotly"`. Note that it is not intended to implement every Pandas plotting function, nor is it intended to replicate the behaviour of every argument, although per the changes below, `x` and `y` should behave similarly. ([#2336](https://github.com/plotly/plotly.py/pull/2336))
10-
- New datasets have been added to `plotly.express.data`: `stocks`, `experiment`, `short_track_wide` and `short_track_long`. ([#2336](https://github.com/plotly/plotly.py/pull/2336))
10+
- New datasets have been added to `plotly.express.data`: `stocks`, `experiment`, `medals_wide` and `medals_long`. ([#2336](https://github.com/plotly/plotly.py/pull/2336))
1111
- plotly `go.Figure` and `go.FigureWidget` now have a `_repr_html_` and a `_repr_mimebundle_` method, which are [standard hooks for integration in systems based on IPython](https://ipython.readthedocs.io/en/stable/config/integrating.html). In particular, with `_repr_html_` plotly figures can now be used within [sphinx-gallery](https://sphinx-gallery.github.io/stable/index.html) without any scraper. These additions should not change anything to the way plotly figures are displayed in notebook environments, since the `_ipython_display_` method (already present in earlier versions) takes precedence over the new methods.
1212

1313
### Updated

doc/python/px-arguments.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,29 @@ By way of example here is the same data, represented in long-form first, and the
5555

5656
```python
5757
import plotly.express as px
58-
long_df = px.data.short_track_long()
58+
long_df = px.data.medals_long()
5959
long_df
6060
```
6161

6262
```python
6363
import plotly.express as px
64-
wide_df = px.data.short_track_wide()
64+
wide_df = px.data.medals_wide()
6565
wide_df
6666
```
6767

6868
Plotly Express can produce the same plot from either form:
6969

7070
```python
7171
import plotly.express as px
72-
long_df = px.data.short_track_long()
72+
long_df = px.data.medals_long()
7373

7474
fig = px.bar(long_df, x="nation", y="count", color="medal", title="Long-Form Input")
7575
fig.show()
7676
```
7777

7878
```python
7979
import plotly.express as px
80-
wide_df = px.data.short_track_wide()
80+
wide_df = px.data.medals_wide()
8181

8282
fig = px.bar(wide_df, x="nation", y=["gold", "silver", "bronze"], title="Wide-Form Input")
8383
fig.show()
@@ -87,7 +87,7 @@ You might notice that y-axis and legend labels are slightly different for the se
8787

8888
```python
8989
import plotly.express as px
90-
wide_df = px.data.short_track_wide()
90+
wide_df = px.data.medals_wide()
9191

9292
fig = px.bar(wide_df, x="nation", y=["gold", "silver", "bronze"], title="Wide-Form Input, relabelled",
9393
labels={"value": "count", "variable": "medal"})

doc/python/wide-form.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,29 @@ By way of example here is the same data, represented in long-form first, and the
5454

5555
```python
5656
import plotly.express as px
57-
long_df = px.data.short_track_long()
57+
long_df = px.data.medals_long()
5858
long_df
5959
```
6060

6161
```python
6262
import plotly.express as px
63-
wide_df = px.data.short_track_wide()
63+
wide_df = px.data.medals_wide()
6464
wide_df
6565
```
6666

6767
Plotly Express can produce the same plot from either form:
6868

6969
```python
7070
import plotly.express as px
71-
long_df = px.data.short_track_long()
71+
long_df = px.data.medals_long()
7272

7373
fig = px.bar(long_df, x="nation", y="count", color="medal", title="Long-Form Input")
7474
fig.show()
7575
```
7676

7777
```python
7878
import plotly.express as px
79-
wide_df = px.data.short_track_wide()
79+
wide_df = px.data.medals_wide()
8080

8181
fig = px.bar(wide_df, x="nation", y=["gold", "silver", "bronze"], title="Wide-Form Input")
8282
fig.show()
@@ -88,7 +88,7 @@ You might notice that y-axis and legend labels are slightly different for the se
8888

8989
```python
9090
import plotly.express as px
91-
wide_df = px.data.short_track_wide()
91+
wide_df = px.data.medals_wide()
9292

9393
fig = px.bar(wide_df, x="nation", y=["gold", "silver", "bronze"], title="Wide-Form Input, relabelled",
9494
labels={"value": "count", "variable": "medal"})
@@ -99,9 +99,9 @@ Plotly Express figures created using wide-form data can be [styled just like any
9999

100100
```python
101101
import plotly.express as px
102-
wide_df = px.data.short_track_wide()
102+
wide_df = px.data.medals_wide()
103103

104-
fig = px.bar(wide_df, x="nation", y=["gold", "silver", "bronze"],
104+
fig = px.bar(wide_df, x="nation", y=["gold", "silver", "bronze"],
105105
title="Wide-Form Input, styled",
106106
labels={"value": "Medal Count", "variable": "Medal", "nation": "Olympic Nation"},
107107
color_discrete_map={"gold": "gold", "silver": "silver", "bronze": "#c96"},
@@ -113,11 +113,11 @@ fig.show()
113113

114114
### Data Frames with Named Indexes
115115

116-
Pandas `DataFrames` support not only column names and "row names" via the value of `index`, but the indexes themselves can be named. Here is how to assign one column of the wide sample data frame above as the index, and to name the column index. The result "indexed" sample data frame can also be obtained by calling `px.data.short_track_wide(indexed=True)`
116+
Pandas `DataFrames` support not only column names and "row names" via the value of `index`, but the indexes themselves can be named. Here is how to assign one column of the wide sample data frame above as the index, and to name the column index. The result "indexed" sample data frame can also be obtained by calling `px.data.medals_wide(indexed=True)`
117117

118118
```python
119119
import plotly.express as px
120-
wide_df = px.data.short_track_wide()
120+
wide_df = px.data.medals_wide()
121121
wide_df = wide_df.set_index("nation")
122122
wide_df.columns.name = "medals"
123123
wide_df
@@ -127,7 +127,7 @@ When working with a data frame like the one above, you can pass the index refere
127127

128128
```python
129129
import plotly.express as px
130-
wide_df = px.data.short_track_wide(indexed=True)
130+
wide_df = px.data.medals_wide(indexed=True)
131131

132132
fig = px.bar(wide_df, x=wide_df.index, y=wide_df.columns)
133133
fig.show()
@@ -137,7 +137,7 @@ If you transpose `x` and `y`, thereby assigning the columns to `x`, the orientat
137137

138138
```python
139139
import plotly.express as px
140-
wide_df = px.data.short_track_wide(indexed=True)
140+
wide_df = px.data.medals_wide(indexed=True)
141141

142142
fig = px.bar(wide_df, x=wide_df.columns, y=wide_df.index)
143143
fig.show()
@@ -149,7 +149,7 @@ For bar, scatter, line and area charts, this pattern of assigning `x=df.index` a
149149

150150
```python
151151
import plotly.express as px
152-
wide_df = px.data.short_track_wide(indexed=True)
152+
wide_df = px.data.medals_wide(indexed=True)
153153

154154
fig = px.bar(wide_df)
155155
fig.show()
@@ -170,7 +170,7 @@ If you specify neither `x` nor `y`, you can specify whether the Y or X xaxis is
170170

171171
```python
172172
import plotly.express as px
173-
wide_df = px.data.short_track_wide(indexed=True)
173+
wide_df = px.data.medals_wide(indexed=True)
174174

175175
fig = px.bar(wide_df, orientation="h")
176176
fig.show()
@@ -183,7 +183,7 @@ In the examples above, the columns of the wide data frame are always assigned to
183183

184184
```python
185185
import plotly.express as px
186-
wide_df = px.data.short_track_wide(indexed=False)
186+
wide_df = px.data.medals_wide(indexed=False)
187187

188188
fig = px.bar(wide_df, x="nation", y=["gold", "silver", "bronze"], facet_col="variable", color="nation")
189189
fig.show()
@@ -193,7 +193,7 @@ If using a data frame's named indexes, either explicitly or relying on the defau
193193

194194
```python
195195
import plotly.express as px
196-
wide_df = px.data.short_track_wide(indexed=True)
196+
wide_df = px.data.medals_wide(indexed=True)
197197

198198
fig = px.bar(wide_df, facet_col="medal", color=wide_df.index)
199199
fig.show()
@@ -228,7 +228,7 @@ We can also leverage the long-form portion of the data frame, for example to col
228228
import plotly.express as px
229229
mixed_df = px.data.experiment(indexed=True)
230230

231-
fig = px.violin(mixed_df, y=["experiment_1", "experiment_2", "experiment_3"],
231+
fig = px.violin(mixed_df, y=["experiment_1", "experiment_2", "experiment_3"],
232232
color="gender", facet_col="group", hover_data=[mixed_df.index])
233233
fig.show()
234234
```
@@ -239,7 +239,7 @@ And of course, we can reassign `variable` to another argument as well, in this c
239239
import plotly.express as px
240240
mixed_df = px.data.experiment(indexed=True)
241241

242-
fig = px.box(mixed_df, x="group", y=["experiment_1", "experiment_2", "experiment_3"],
242+
fig = px.box(mixed_df, x="group", y=["experiment_1", "experiment_2", "experiment_3"],
243243
color="gender", facet_col="variable", hover_data=[mixed_df.index])
244244
fig.show()
245245
```

packages/python/plotly/plotly/data/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def experiment(indexed=False):
136136
return df
137137

138138

139-
def short_track_wide(indexed=False):
139+
def medals_wide(indexed=False):
140140
"""
141141
This dataset represents the medal table for Olympic Short Track Speed Skating for the
142142
top three nations as of 2020.
@@ -147,14 +147,14 @@ def short_track_wide(indexed=False):
147147
If `indexed` is True, the 'nation' column is used as the index and the column index
148148
is named 'medal'
149149
"""
150-
df = _get_dataset("short_track")
150+
df = _get_dataset("medals")
151151
if indexed:
152152
df = df.set_index("nation")
153153
df.columns.name = "medal"
154154
return df
155155

156156

157-
def short_track_long(indexed=False):
157+
def medals_long(indexed=False):
158158
"""
159159
This dataset represents the medal table for Olympic Short Track Speed Skating for the
160160
top three nations as of 2020.
@@ -164,7 +164,7 @@ def short_track_long(indexed=False):
164164
`['nation', 'medal', 'count']`.
165165
If `indexed` is True, the 'nation' column is used as the index.
166166
"""
167-
df = _get_dataset("short_track").melt(
167+
df = _get_dataset("medals").melt(
168168
id_vars=["nation"], value_name="count", var_name="medal"
169169
)
170170
if indexed:

0 commit comments

Comments
 (0)