Spaces:
Running
Running
File size: 6,816 Bytes
b9a0f21 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
```python
import numpy as np
np.random.seed(1)
```
## Data sources
The `.hvplot()` plotting API supports a wide range of data sources. Most frequently, a special import can be executed to register the `.hvplot` accessor on a data type. For instance, importing `hvplot.pandas` registers the `.hvplot` accessor on Pandas `DataFrame` and `Series` objects, allowing to call `df.hvplot.line()`.
Among the data sources introduced below, Pandas](https://pandas.pydata.org) is the only library that doesn't need to be installed separately as it is a direct dependency of hvPlot.
:::{note}
Supporting so many data sources is hard work! We are aware that the support for some of them isn't as good as we would like. If you encounter any issue please report it <a href='https://github.com/holoviz/hvplot/'>on GitHub</a>, we always welcome Pull Requests too!
:::
### Columnar/tabular
#### Pandas
`.hvplot()` supports [Pandas](https://pandas.pydata.org) `DataFrame` and `Series` objects.
```python
import hvplot.pandas # noqa
import pandas as pd
df_pandas = pd.DataFrame(np.random.randn(1000, 4), columns=list('ABCD')).cumsum()
df_pandas.head(2)
```
```python
# Pandas DataFrame
df_pandas.hvplot.line(height=150)
```
```python
# Pandas Series
s_pandas = df_pandas['A']
s_pandas.hvplot.line(height=150)
```
#### [Dask](https://www.dask.org)
`.hvplot()` supports [Dask](https://www.dask.org) `DataFrame` and `Series` objects.
```python
import hvplot.dask # noqa
import dask
df_dask = dask.dataframe.from_pandas(df_pandas, npartitions=2)
df_dask
```
```python
# Dask DataFrame
df_dask.hvplot.line(height=150)
```
```python
# Dask Series
s_dask = df_dask['A']
s_dask.hvplot.line(height=150)
```
#### GeoPandas
`.hvplot()` supports [GeoPandas](https://geopandas.org) `GeoDataFrame` objects.
```python
import hvplot.pandas # noqa
import geopandas as gpd
p_geometry = gpd.points_from_xy(
x=[12.45339, 12.44177, 9.51667, 6.13000],
y=[41.90328, 43.93610, 47.13372, 49.61166],
crs='EPSG:4326'
)
p_names = ['Vatican City', 'San Marino', 'Vaduz', 'Luxembourg']
gdf = gpd.GeoDataFrame(dict(name=p_names), geometry=p_geometry)
gdf.head(2)
```
```python
# GeoPandas GeoDataFrame
gdf.hvplot.points(geo=True, tiles='CartoLight', frame_height=150, data_aspect=0.5)
```
#### Ibis
[Ibis](https://ibis-project.org/) is the "portable Python dataframe library", it provides a unified interface to many data backends (e.g. DuckDB, SQLite, SnowFlake, Google BigQuery). `.hvplot()` supports [Ibis](https://ibis-project.org/) `Expr` objects.
```python
import hvplot.ibis # noqa
import ibis
table = ibis.memtable(df_pandas.reset_index())
table
```
```python
# Ibis Expr
table.hvplot.line(x='index', height=150)
```
#### Polars
:::{note}
Added in version `0.9.0`.
:::
:::{important}
While other data sources like `Pandas` or `Dask` have built-in support in HoloViews, as of version 1.17.1 this is not yet the case for `Polars`. You can track this [issue](https://github.com/holoviz/holoviews/issues/5939) to follow the evolution of this feature in HoloViews. Internally hvPlot simply selects the columns that contribute to the plot and casts them to a Pandas object using Polars' `.to_pandas()` method.
:::
```python
import hvplot.polars # noqa
import polars
df_polars = polars.from_pandas(df_pandas)
df_polars.head(2)
```
`.hvplot()` supports [Polars](https://www.pola.rs/) `DataFrame`, `LazyFrame` and `Series` objects.
```python
# Polars DataFrame
df_polars.hvplot.line(y=['A', 'B', 'C', 'D'], height=150)
```
```python
# Polars LazyFrame
df_polars.lazy().hvplot.line(y=['A', 'B', 'C', 'D'], height=150)
```
```python
# Polars Series
df_polars['A'].hvplot.line(height=150)
```
#### Rapids cuDF
:::{important}
[Rapids cuDF](https://docs.rapids.ai/api/cudf) is a Python **GPU** DataFrame library. Neither hvPlot's nor HoloViews' test suites currently run on a GPU part of their CI, as of versions 0.9.0 and 1.17.1, respectively. This is due to the non availability of machines equipped with a GPU on the free CI system we rely on (Github Actions). Therefore it's possible that support for cuDF gets degraded in hvPlot without us noticing it immediately. Please report any issue you might encounter.
:::
`.hvplot()` supports [cuDF](https://docs.rapids.ai/api/cudf) `DataFrame` and `Series` objects.
#### Fugue
:::{admonition} Experimental
:class: caution
[Fugue](https://fugue-tutorials.readthedocs.io/) support, added in version `0.9.0`, is experimental and may change in future versions.
:::
hvPlot adds the `hvplot` plotting extension to FugueSQL.
```python
import hvplot.fugue # noqa
import fugue
fugue.api.fugue_sql(
"""
OUTPUT df_pandas USING hvplot:line(
height=150,
)
"""
)
```
### Multidimensional
#### Xarray
`.hvplot()` supports [XArray](https://xarray.pydata.org) `Dataset` and `DataArray` labelled multidimensional objects.
```python
import hvplot.xarray # noqa
import xarray as xr
ds = xr.Dataset({
'A': (['x', 'y'], np.random.randn(100, 100)),
'B': (['x', 'y'], np.random.randn(100, 100))},
coords={'x': np.arange(100), 'y': np.arange(100)}
)
ds
```
```python
# Xarray Dataset
ds.hvplot.hist(height=150)
```
```python
# Xarray DataArray
ds['A'].hvplot.image(height=150)
```
### Catalog
#### Intake
`.hvplot()` supports [Intake](https://github.com/ContinuumIO/intake) `DataSource` objects.
### Streaming
#### Streamz
`.hvplot()` supports [Streamz](https://streamz.readthedocs.io) `DataFrame`, `DataFrames`, `Series` and `Seriess` objects.
### Graph
#### NetworkX
The hvPlot [NetworkX](https://networkx.github.io) plotting API is meant as a drop-in replacement for the `networkx.draw` methods. The `draw` and other `draw_<>` methods are available in the `hvplot.networkx` module.
```python
import hvplot.networkx as hvnx
import networkx as nx
G = nx.petersen_graph()
hvnx.draw(G, with_labels=True, height=150)
```
## Plotting extensions
hvPlot is capable of producing plots with [Bokeh](https://www.bokeh.org) (default, interactive), [Matplotlib](https://matplotlib.org) (static) and [Plotly](https://plotly.com/python/) (interactive). Under the hood, hvPlot delegates plotting to HoloViews which itself calls these plotting libraries. This is why we call hvPlot a high-level plotting library!
Follow the [Plotting Extensions Guide](Plotting_Extensions.ipynb) for more information.
:::{note}
Similarly to having to support many data sources, supporting three plotting extensions is hard work! We are aware they are not supported equivalently, you will get best support for Bokeh, followed by Matplotlib and finally Plotly. If you encounter any issue with a specific plotting extension please report it <a href='https://github.com/holoviz/hvplot/'>on GitHub</a>, we always welcome Pull Requests too!
:::
|