Skip to content

Commit 2e81618

Browse files
committed
Update px-arguments.md
1 parent bf18732 commit 2e81618

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

doc/python/px-arguments.md

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ jupyter:
55
text_representation:
66
extension: .md
77
format_name: markdown
8-
format_version: '1.2'
9-
jupytext_version: 1.4.2
8+
format_version: '1.3'
9+
jupytext_version: 1.14.7
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.7
23+
version: 3.10.4
2424
plotly:
2525
description: Input data arguments accepted by Plotly Express functions
2626
display_as: file_settings
@@ -37,7 +37,9 @@ jupyter:
3737

3838
[Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on a variety of types of data](/python/px-arguments/) and produces [easy-to-style figures](/python/styling-plotly-express/).
3939

40-
Plotly Express provides functions to visualize a variety of types of data. Most functions such as `px.bar` or `px.scatter` expect to operate on column-oriented data of the type you might store in a Pandas `DataFrame` (in either "long" or "wide" format, see below). [`px.imshow` operates on matrix-like data](/python/imshow/) you might store in a `numpy` or `xarray` array and functions like [`px.choropleth` and `px.choropleth_mapbox` can operate on geographic data](/python/maps/) of the kind you might store in a GeoPandas `GeoDataFrame`. This page details how to provide column-oriented data to most Plotly Express functions.
40+
Plotly Express provides functions to visualize a variety of types of data. Most functions such as `px.bar` or `px.scatter` expect to operate on column-oriented data of the type you might store in a `DataFrame` (in either "long" or "wide" format, see below). These functions use Pandas internally to process the data, but also accept other types of DataFrames as arguments. See the **Input Data as Non-Pandas DataFrames** section below for more details.
41+
42+
[`px.imshow` operates on matrix-like data](/python/imshow/) you might store in a `numpy` or `xarray` array and functions like [`px.choropleth` and `px.choropleth_mapbox` can operate on geographic data](/python/maps/) of the kind you might store in a GeoPandas `GeoDataFrame`. This page details how to provide column-oriented data to most Plotly Express functions.
4143

4244

4345

@@ -166,6 +168,38 @@ fig = px.bar(df, x='year', y=gdp, color='continent', labels={'y':'gdp'},
166168
fig.show()
167169
```
168170

171+
### Input Data as Non-Pandas `DataFrame`s
172+
173+
**New in 5.16**
174+
175+
In the examples above, we've used Pandas DataFrames. You can also provide another type of DataFrame to the `data_frame` argument if that DataFrame has a `to_pandas` method or supports the [Python dataframe interchange protocol](https://data-apis.org/dataframe-protocol/latest/index.html), for example, a [Polars](https://www.pola.rs/) DataFrame.
176+
177+
Plotly Express uses Pandas internally to process the data. When you provide a Non-Pandas DataFrame to the `data_frame` argument of a Plotly Express function, the entire DataFrame is converted to a Pandas DataFrame.
178+
179+
If you are using a type of DataFrame that doesn't have a `to_pandas` method, but supports the Python dataframe interchange protocol, you'll need to have Pandas version 2.0.3 or later installed.
180+
181+
If you are using Polars, you'll need to install `pyarrow`, which is used by its [`to_pandas` method](
182+
https://pola-rs.github.io/polars/py-polars/html/reference/dataframe/api/polars.DataFrame.to_pandas.html)
183+
184+
In this example, we use a Polars DataFrame.
185+
186+
```python
187+
import polars as pl
188+
import plotly.express as px
189+
190+
wide_df = pl.DataFrame(
191+
{
192+
"nation": ["South Korea", "China", "Canada"],
193+
"gold": [24, 10, 9],
194+
"silver": [13, 15, 12],
195+
"bronze": [9, 12, 12],
196+
}
197+
)
198+
199+
fig = px.bar(wide_df, x="nation", y=["gold", "silver", "bronze"], title="Wide-Form Input")
200+
fig.show()
201+
```
202+
169203
### Input Data as array-like columns: NumPy arrays, lists...
170204

171205
`px` arguments can also be array-like objects such as lists, NumPy arrays, in both long-form or wide-form (for certain functions).
@@ -243,4 +277,4 @@ fig = px.bar(df, x='year', y=gdp, color='continent', labels={'y':'log gdp'},
243277
hover_data=['country'],
244278
title='Evolution of world GDP')
245279
fig.show()
246-
```
280+
```

0 commit comments

Comments
 (0)