### Setup Development Environment with Pixi Source: https://github.com/holoviz/hvplot/blob/main/doc/developer_guide.md Run this command to create a development environment, install hvPlot in editable mode, download test datasets, and install pre-commit hooks. This command may take a minute or two to complete. ```bash pixi run setup-dev ``` -------------------------------- ### Install hvPlot from source Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/installation.md Install hvPlot from its GitHub repository by cloning the repository and running the pip install command in the root directory. ```bash pip install -e . ``` -------------------------------- ### Install Pre-commit Hooks Manually Source: https://github.com/holoviz/hvplot/blob/main/doc/developer_guide.md Manually installs pre-commit hooks if not using pixi for installation. ```bash pre-commit install ``` -------------------------------- ### Install hvPlot with uv Source: https://github.com/holoviz/hvplot/blob/main/doc/tutorials/getting_started.ipynb Use uv, a fast Python package installer, to install hvplot. ```bash uv pip install hvplot ``` -------------------------------- ### Run Example Tests Source: https://github.com/holoviz/hvplot/blob/main/doc/developer_guide.md Executes all Jupyter Notebook example tests using the 'test-example' pixi task. ```bash pixi run test-example ``` -------------------------------- ### Install Pre-commit Hooks Source: https://github.com/holoviz/hvplot/blob/main/doc/developer_guide.md Installs pre-commit hooks for linting and formatting the source code. ```bash pixi run lint-install ``` -------------------------------- ### Install hvPlot pre-releases using uv Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/installation.md Use this command to install pre-release versions (alpha, beta, RC) of hvPlot from PyPI using uv. ```bash uv pip install hvplot --prerelease allow ``` -------------------------------- ### Install hvPlot using uv Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/installation.md Use this command to install the latest stable version of hvPlot from PyPI using uv. ```bash uv pip install hvplot ``` -------------------------------- ### Install hvSampledata with pip Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api/index.md Install the hvsampledata package using pip if hvPlot was installed with minimal dependencies. ```bash pip install hvsampledata ``` -------------------------------- ### Xarray Example Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api/manual/hvplot.hvPlot.line.ipynb Provides an example of plotting a line from an xarray Dataset, specifically showing the evolution of air temperature at a fixed location. ```APIDOC ## hvplot.hvPlot.line with Xarray ### Description Plots time-series data from an xarray Dataset. ### Method Signature `hvplot.hvPlot.line(y=None, ...)` ### Parameters * **y** (str, optional): Variable name from the xarray Dataset to plot on the y-axis. ### Request Example ```python import hvplot.xarray ds = hvplot.sampledata.air_temperature("xarray").sel(lon=285.,lat=40.) ds.hvplot.line(y="air") ``` ``` -------------------------------- ### Install hvPlot pre-releases using pip Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/installation.md Use this command to install pre-release versions (alpha, beta, RC) of hvPlot from PyPI using pip. ```bash pip install hvplot --pre ``` -------------------------------- ### Install hvPlot from conda-forge Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/installation.md Install hvPlot from the community-maintained conda-forge channel using conda. ```bash conda install conda-forge::hvplot ``` -------------------------------- ### Get hvPlot help via command line Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Introduction.ipynb Outside an interactive environment, use `hvplot.help()` to get information about plot kinds. For detailed options, refer to the plotting options documentation. ```python hvplot.help('line') ``` -------------------------------- ### Install hvPlot with Pip Source: https://github.com/holoviz/hvplot/blob/main/README.md Use this command to install hvPlot using the Pip package manager. ```bash pip install hvplot ``` -------------------------------- ### Install in Specific Test Environment Source: https://github.com/holoviz/hvplot/blob/main/doc/developer_guide.md Installs hvPlot in a specific pixi test environment, e.g., 'test-core'. ```bash pixi run -e test-core install ``` -------------------------------- ### Install hvPlot from defaults channel Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/installation.md Install hvPlot from the Anaconda defaults channel using conda. Note: This channel may have licensing restrictions. ```bash conda install defaults::hvplot ``` -------------------------------- ### Get Plotting Help Source: https://github.com/holoviz/hvplot/blob/main/README.md Use hvplot.help() to retrieve documentation for specific plot kinds, such as 'scatter'. In notebook environments, standard help() and ? syntax also work. ```python hvplot.help(kind='scatter') ``` -------------------------------- ### Xarray example Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api/manual/hvplot.hvPlot.hexbin.ipynb Creates a hexbin plot from an xarray DataArray, aggregating temperature readings and using a logarithmic color scale. ```APIDOC ## Xarray example ### Description Creates a hexbin plot from an xarray DataArray, aggregating temperature readings and using a logarithmic color scale. ### Usage ```python import hvplot.xarray # noqa import numpy as np da = hvplot.sampledata.air_temperature("xarray").sel(time="2014-02-25 12:00") da.hvplot.hexbin( x="lon", y="lat", cmap="inferno", bgcolor="#020210", data_aspect=1, frame_width=400, C="air", reduce_function=np.mean, clabel="Air temperature (K)", logz=True, gridsize=30, ) ``` ``` -------------------------------- ### KDE from Long-Form Data by Category Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api/manual/hvplot.hvPlot.kde.ipynb Compares distributions across categories using the `by` keyword. This example plots the distribution of bill lengths for each penguin species. ```python import hvplot.pandas # noqa df = hvplot.sampledata.penguins("pandas") df.hvplot.kde(y="bill_length_mm", by="species") ``` -------------------------------- ### Xarray Example: Air Temperature Evolution Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api/manual/hvplot.hvPlot.line.ipynb Plots the evolution of air temperature from an xarray Dataset at a specific location. Requires hvplot.xarray to be imported. ```python import hvplot.xarray ds = hvplot.sampledata.air_temperature("xarray").sel(lon=285.,lat=40.) ds.hvplot.line(y="air") ``` -------------------------------- ### Load xarray air temperature dataset Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Gridded_Data.ipynb Imports necessary libraries and loads the sample air temperature dataset from xarray. This sets up the data for subsequent plotting examples. ```python import xarray as xr import hvplot.xarray # noqa air_ds = xr.tutorial.open_dataset('air_temperature').load() air = air_ds.air air_ds ``` -------------------------------- ### Create hvPlot environment Source: https://github.com/holoviz/hvplot/blob/main/doc/tutorials/getting_started.ipynb Create a conda environment with all necessary dependencies to run hvPlot guides locally. This includes hvplot and its core dependencies like HoloViews, Datashader, and Pandas. ```bash conda create -n hvplot-env -c conda-forge --override-channels hvplot geoviews datashader xarray pandas geopandas dask networkx intake intake-xarray intake-parquet s3fs scipy spatialpandas pooch rasterio fiona plotly matplotlib hvsampledata jupyterlab ``` -------------------------------- ### Build Documentation Source: https://github.com/holoviz/hvplot/blob/main/doc/developer_guide.md Builds the hvPlot documentation using the 'docs-build' pixi task. ```bash pixi run docs-build ``` -------------------------------- ### Install hvSampledata with conda Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api/index.md Install the hvsampledata package using conda if hvPlot was installed with minimal dependencies. ```bash conda install conda-forge::hvsampledata ``` -------------------------------- ### Launch Jupyter Lab with Development Environment Source: https://github.com/holoviz/hvplot/blob/main/doc/developer_guide.md Launches Jupyter Lab using the default pixi development environment. ```bash pixi run lab ``` -------------------------------- ### Generating Similar Plot with HoloViews Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api_compatibility/pandas/Pandas_API.ipynb This example shows how to generate a similar plot to Pandas' multi-column grouped histograms using HoloViews directly, as this specific functionality is not yet supported in hvPlot. ```python import holoviews as hv from holoviews.operation import histogram ds = hv.Dataset(data, kdims=['a', 'b'], vdims=['c', 'd']) dsg = ds.groupby(['a', 'b']) ( hv.NdLayout(histogram(dsg, dimension='c')) * hv.NdLayout(histogram(dsg, dimension='d')) ).opts( hv.opts.Histogram(height=100, width=800) ).cols(1) ``` -------------------------------- ### Chaining Interactive Methods for Complex Plots Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Interactive.ipynb Chain multiple interactive methods and widgets to control different aspects of the data pipeline. This example combines selection, quantile calculation, and plotting. ```python q = pnw.FloatSlider(name='quantile', start=0, end=1) (ds.air.interactive(loc='left') .sel(time=pnw.DiscreteSlider) .quantile(q=q, dim='lon') .hvplot(aspect=1)) ``` -------------------------------- ### List Available Tile Sources Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/plotting_options/geographic.ipynb Prints the available tile sources from HoloViews and GeoViews. Requires importing the respective libraries. ```python import geoviews as gv import holoviews as hv print("HoloViews tiles:", *hv.element.tiles.tile_sources, sep=" ", end="\n\n") print("GeoViews tiles:", *gv.tile_sources.tile_sources, sep=" ") ``` -------------------------------- ### Install hvPlot with Conda Source: https://github.com/holoviz/hvplot/blob/main/README.md Use this command to install hvPlot using the Conda package manager. ```bash conda install hvplot ``` -------------------------------- ### Instantiate Explorer with Options Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Explorer.ipynb Instantiates the hvPlot Explorer and pre-customizes the plot using options such as title and width. ```python data.hvplot.explorer(title='Penguins', width=200) ``` -------------------------------- ### Install hvPlot pre-releases from pyviz/label/dev Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/installation.md Install pre-release versions of hvPlot from the pyviz development channel using conda. ```bash conda install pyviz/label/dev::hvplot ``` -------------------------------- ### Create and Display Explorer Instance Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Explorer.ipynb Loads the penguins dataset and creates an hvPlot Explorer instance from it. The explorer object is then displayed. ```python from bokeh.sampledata.penguins import data as df df.head(2) ``` ```python hvexplorer = df.hvplot.explorer() hvexplorer ``` -------------------------------- ### Control Smoothing with Bandwidth Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api/manual/hvplot.hvPlot.kde.ipynb Demonstrates how to control the smoothness of a KDE plot using the `bandwidth` argument. Smaller values increase detail. Defaults to Scott's rule of thumb if not set. ```python import hvplot.pandas # noqa df = hvplot.sampledata.earthquakes("pandas") df.hvplot.kde( y='depth', bandwidth=0.1, width=300, title='bandwidth=0.1' ) + df.hvplot.kde( y='depth', bandwidth=0.5, width=300, shared_axes=False, title='bandwidth=0.5' ) ``` -------------------------------- ### Control Smoothing with `bandwidth` Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api/manual/hvplot.hvPlot.kde.ipynb Demonstrates how to control the smoothness of the KDE plot using the `bandwidth` argument. Smaller values result in more detail, while not setting it uses Scott's rule of thumb. ```APIDOC ## Control smoothing with `bandwidth` You can control the smoothness of the estimate using the `bandwidth` argument that accepts a positive numerical value. Smaller values yield more detail. When not set, the bandwidth is internally computed using Scott's rule of thumb. ```python import hvplot.pandas # noqa df = hvplot.sampledata.earthquakes("pandas") df.hvplot.kde( y='depth', bandwidth=0.1, width=300, title='bandwidth=0.1' ) + df.hvplot.kde( y='depth', bandwidth=0.5, width=300, shared_axes=False, title='bandwidth=0.5' ) ``` ``` -------------------------------- ### Load Sample Data with Pandas Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Plotting.ipynb Load the apple_stocks sample dataset as a pandas DataFrame. This is useful for demonstrating plotting capabilities. ```python from hvplot.sampledata import apple_stocks, nyc_taxi_remote, penguins apple = apple_stocks('pandas') print(type(apple)) ``` -------------------------------- ### Load Sample Data Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Plotting_Extensions.ipynb Loads the apple_stocks dataset into a pandas DataFrame for plotting. ```python from hvplot.sampledata import apple_stocks df = apple_stocks('pandas') ``` -------------------------------- ### Activate Development Shell Source: https://github.com/holoviz/hvplot/blob/main/doc/developer_guide.md Activates the development shell, equivalent to sourcing a virtual environment. ```bash pixi shell ``` -------------------------------- ### Image vs. Quadmesh for Irregular Grids Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api/manual/hvplot.hvPlot.image.ipynb Explains the difference between `Image` and `Quadmesh` elements and demonstrates how to handle potentially irregular grids by adjusting `rtol` or using `quadmesh`. ```APIDOC ## Image vs. Quadmesh The `hvplot.image` method, which constructs a HoloViews `Image` element, validates input data for regular sampling. If the data is not sampled with sufficient precision, an exception may suggest using the `Quadmesh` element instead. To address this for `Image` elements, you can increase the allowed deviation in sample spacing by globally setting `hv.config.image_rtol`. Otherwise, consider using the `quadmesh` method. ```python import hvplot.xarray # noqa ds = hvplot.sampledata.air_temperature("xarray").sel(time="2014-02-25 12:00") # Emulate irregular grid ds.coords["lat"] = ds.coords["lat"]**2 ds.hvplot.image(x="lon", y="lat", z="air", cmap="blues", width=400, height=400) ``` ``` -------------------------------- ### Save Plot to PNG Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Viewing.ipynb Export a HoloViews plot as a PNG image. This requires Selenium and PhantomJS to be installed. ```python from pathlib import Path Path('test.html').unlink(missing_ok=True) Path('test.png').unlink(missing_ok=True) ``` -------------------------------- ### Load Sample xarray Dataset Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Interactive.ipynb Loads the 'air_temperature' dataset from xarray's tutorial data. ```python ds = xr.tutorial.load_dataset('air_temperature') ds ``` -------------------------------- ### Simple Explorer with Pandas DataFrame Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api/manual/hvplot.hvPlot.explorer.ipynb Demonstrates how to create a basic interactive explorer for a pandas DataFrame using hvplot. This example initializes the explorer and sets initial parameters for plotting, such as x-axis, y-axis, and grouping variables. ```python import hvplot.pandas df = hvplot.sampledata.penguins("pandas") hvexplorer = df.hvplot.explorer() # Start: only required for building the site hvexplorer.param.update(x='bill_length_mm', y_multi=['bill_depth_mm'], by=['species']) hvexplorer.labels.title = 'Penguins Scatter' # End hvexplorer ``` -------------------------------- ### Create Geographic Plot with GeoViews Source: https://github.com/holoviz/hvplot/blob/main/doc/tutorials/getting_started.ipynb Generates a quadmesh plot with advanced mapping features using GeoViews. Requires GeoViews to be installed. ```python import cartopy.crs as crs air_ds.hvplot.quadmesh( 'lon', 'lat', projection=crs.Orthographic(-90, 30), project=True, global_extent=True, cmap='viridis', coastline=True ) ``` -------------------------------- ### Import hvplot for Pandas DataFrames Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api/index.md Install the hvplot namespace on a Pandas DataFrame to enable plotting. This registers an accessor for convenient plotting. ```python import pandas as pd import hvplot.pandas # noqa df = pd.DataFrame() df.hvplot.scatter() # or df.hvplot(kind='scatter') ``` -------------------------------- ### hvPlot Scatter Plot Example Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api_compatibility/pandas/index.ipynb Generates a scatter plot using hvPlot. This returns a HoloViews object, which wraps the dataset and represents a plot. ```python plot = df.hvplot.scatter('bill_length_mm', 'bill_depth_mm', hover_cols=['species']) ``` -------------------------------- ### Initialize hvplot with Fugue Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/data_libraries.ipynb Import the hvplot extension for Fugue and use the `fugue_sql` function to define a FugueSQL query that outputs a line plot. This enables plotting directly from FugueSQL. ```python import hvplot.fugue # noqa import fugue fugue.api.fugue_sql( """ OUTPUT df_pandas USING hvplot:line( height=150, ) """ ) ``` -------------------------------- ### Xarray Timeseries Data Loading Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Timeseries_Data.ipynb Loads the 'air_temperature' dataset from xarray's tutorial data, demonstrating the setup for using hvplot with xarray. ```python import xarray as xr import hvplot.xarray # noqa air_ds = xr.tutorial.open_dataset('air_temperature').load() air_ds ``` -------------------------------- ### Create Interactive Xarray Data Pipeline with Widgets Source: https://github.com/holoviz/hvplot/blob/main/doc/index.md Demonstrates creating an interactive data pipeline from an xarray DataArray using `.interactive()`. It allows adjusting a time index with a slider and calculates the difference between a selected time step and the overall mean. ```python import hvplot.xarray import panel as pn import xarray as xr w_time = pn.widgets.IntSlider(name='time', start=0, end=10) da = xr.tutorial.open_dataset('air_temperature').air da.interactive.isel(time=w_time).mean().item() - da.mean().item() ``` -------------------------------- ### Plotting points with custom projection Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Geographic_Data.ipynb Plots geographic points with coastline and a specified orthographic projection centered over North America. Requires GeoViews to be installed. ```python airports.hvplot.points( 'Longitude', 'Latitude', color='red', alpha=0.2, coastline=True, projection=ccrs.Orthographic(-90, 30) ) ``` -------------------------------- ### Line Dash Styles (Bokeh) Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api/manual/hvplot.hvPlot.line.ipynb Demonstrates various line dash styles including named options and custom dash patterns for the Bokeh backend. ```python import hvplot.pandas import pandas as pd df = pd.DataFrame({"x": [0, 1, 2, 3], "y": [0, 1, 4, 9]}) plot_opts = dict(x="x", y="y", width=300, height=200) ( df.hvplot.line(line_dash="dashed", title="dashed", **plot_opts) + df.hvplot.line(line_dash="dotted", title="dotted", **plot_opts) + df.hvplot.line(line_dash="dotdash", title="dotdash", **plot_opts) + df.hvplot.line(line_dash="dashdot", title="dashdot", **plot_opts) + df.hvplot.line(line_dash=(20, 10), title="Dash pattern (20, 10)", **plot_opts) + df.hvplot.line(line_dash=(20, 10, 5), title="Dash pattern (20, 10, 5)", **plot_opts) ).cols(2) ``` -------------------------------- ### Customize groupby widget location Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Widgets.ipynb Changes the position of the automatically generated groupby widget using the 'widget_location' option. This example places the widget at the top-left. ```python flowers.hvplot.bivariate(x='sepal_width', y='sepal_length', width=600, groupby='species', widget_location='left_top') ``` -------------------------------- ### Generate Sample Vector Field Data Source: https://github.com/holoviz/hvplot/blob/main/doc/gallery/big-data/large_vectorfield_downsampled.ipynb Creates a sample dataset with 4,000,000 points for demonstrating vector field visualization. ```python def sample_data(shape=(20, 30)): x = np.linspace(311.9, 391.1, shape[1]) y = np.linspace(-23.6, 24.8, shape[0]) x2d, y2d = np.meshgrid(x, y) u = 10 * (2 * np.cos(2 * np.deg2rad(x2d) + 3 * np.deg2rad(y2d + 30)) ** 2) v = 20 * np.cos(6 * np.deg2rad(x2d)) return x, y, u, v xs, ys, U, V = sample_data(shape=(2000, 2000)) mag = np.sqrt(U**2 + V**2) angle = (np.pi/2.) - np.arctan2(U/mag, V/mag) ds = xr.Dataset({ 'mag': xr.DataArray(mag, dims=('y', 'x'), coords={'y': ys, 'x': xs}), 'angle': xr.DataArray(angle, dims=('y', 'x'), coords={'y': ys, 'x': xs}) }) ds ``` -------------------------------- ### Customizing Tick Formatters in hvPlot Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api_compatibility/pandas/Pandas_API.ipynb Example of setting custom y-axis formatters using format strings and Bokeh TickFormatters, and x-axis formatters with a DatetimeTickFormatter. ```python from bokeh.models.formatters import DatetimeTickFormatter formatter = DatetimeTickFormatter(months='%b %Y') df['A'].plot(yformatter='$%.2f', xformatter=formatter) ``` -------------------------------- ### Run Pre-commit on All Files Manually Source: https://github.com/holoviz/hvplot/blob/main/doc/developer_guide.md Manually runs pre-commit on all files if not using pixi for execution. ```bash pre-commit run --all-files ``` -------------------------------- ### Customizing Axis Labels with Matplotlib Backend Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api_compatibility/pandas/Pandas_API.ipynb Example of setting custom labels for the x and y axes using 'xlabel' and 'ylabel' arguments with the matplotlib backend. ```python df.plot(xlabel="new x", ylabel="new y", backend='matplotlib'); ``` -------------------------------- ### Box Plot using DataFrame.boxplot() Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api_compatibility/pandas/Pandas_API.ipynb Generates a box plot using the `DataFrame.boxplot()` method, which is an alternative interface to `DataFrame.plot.box()`. This example uses the matplotlib backend. ```python df = pd.DataFrame(np.random.rand(10, 5)) df.boxplot(backend='matplotlib') ``` -------------------------------- ### Build Interactive Pipeline with Widgets Source: https://github.com/holoviz/hvplot/blob/main/doc/tutorials/getting_started.ipynb Create an interactive object using .interactive() and integrate the Panel widgets into the data pipeline. This setup allows for dynamic updates of the pipeline's output as widget values change. ```python airi = air.interactive() baseline = airi.sel(lat=w_latitude).mean().item() pipeline = ( airi .sel(lat=w_latitude) .to_dataframe() .drop(columns='lat') .groupby('time').mean() .rolling(w_rolling_window).mean() - baseline ) pipeline.describe() ``` -------------------------------- ### Load Sample Data with Dask Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Plotting.ipynb Load the nyc_taxi_remote sample dataset as a dask DataFrame. This demonstrates handling larger datasets with dask. ```python taxi = nyc_taxi_remote('dask', lazy=True) print(type(taxi)) ``` -------------------------------- ### Interactive Bokeh Plots with .hvplot Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Interactive.ipynb Utilize the `.hvplot` method for fully interactive Bokeh-based plots. This example uses a `FloatSlider` to control the quantile calculation. ```python slider = pnw.FloatSlider(name='quantile', start=0, end=1) ds.air.interactive.quantile(slider, dim='time').hvplot(data_aspect=1) ``` -------------------------------- ### Plotting Multi-Column Grouped Histograms with Pandas Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api_compatibility/pandas/Pandas_API.ipynb In Pandas, the `by` keyword can also be specified in `DataFrame.plot.hist()`. This example demonstrates plotting histograms grouped by multiple columns. ```python data = pd.DataFrame( { "a": np.random.choice(["x", "y", "z"], 1000), "b": np.random.choice(["e", "f", "g"], 1000), "c": np.random.randn(1000), "d": np.random.randn(1000) - 1, }, ) data.plot.hist(by=["a", "b"], figsize=(10, 5), backend='matplotlib'); ``` -------------------------------- ### Initialize hvPlot Explorer Source: https://github.com/holoviz/hvplot/blob/main/doc/tutorials/getting_started.ipynb Instantiate the hvPlot explorer with pre-defined parameters for data exploration. This provides a graphical interface to select and customize plots. ```python explorer = df_penguins.hvplot.explorer(x='bill_length_mm', y='bill_depth_mm', by=['species']) explorer ``` -------------------------------- ### Instantiate Explorer via Method Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Explorer.ipynb Instantiates the hvPlot Explorer using the `.explorer()` method available on the `.hvplot` namespace. This method was added in version 0.9.0. ```python data.hvplot.explorer() ``` -------------------------------- ### Plotting Histogram of Differences with hvPlot Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api_compatibility/pandas/Pandas_API.ipynb This example shows plotting the histogram of the differences between consecutive elements in a column using hvPlot's default behavior. ```python df['A'].diff().hist() ``` -------------------------------- ### Load Sample Datasets in Python Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api/index.md Import hvPlot extensions and load sample datasets into pandas, xarray, rioxarray, and geopandas data structures. ```python import hvplot.pandas # noqa import hvplot.xarray # noqa penguins = hvplot.sampledata.penguins("pandas") air_temp = hvplot.sampledata.air_temperature("xarray") landsat = hvplot.sampledata.landsat_rgb("rioxarray") us_states = hvplot.sampledata.us_states("geopandas") ``` -------------------------------- ### Display unique toolbar in a layout Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/plotting_options/interactivity.ipynb In a layout of plots, a single toolbar is displayed above all plots. This example shows a scatter plot combined with a line plot. ```python import hvplot.pandas import pandas as pd df = pd.DataFrame({"y": [1, 4, 2]}) df.hvplot.scatter(width=300, height=150) + df.hvplot.line(width=300, height=150) ``` -------------------------------- ### Load and display air temperature dataset Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Geographic_Data.ipynb Loads the air temperature dataset from xarray's tutorial data. ```python air_ds = xr.tutorial.open_dataset('air_temperature').load() air_ds ``` -------------------------------- ### Load Sample Data with Pandas Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Plotting_with_Plotly.ipynb Load the 'apple_stocks' dataset into a pandas DataFrame using the hvplot sample data module. This is useful for time-series plotting. ```python from hvplot.sampledata import apple_stocks, nyc_taxi_remote, penguins apple = apple_stocks('pandas') print(type(apple)) apple.head() ``` -------------------------------- ### Timeseries Bar Plot with hvplot (Pandas) Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api/manual/hvplot.hvPlot.bar.ipynb Create a bar plot where the x-axis represents a timeseries. This example uses pandas DataFrames and requires hvplot.pandas. ```python import hvplot.pandas df = hvplot.sampledata.stocks("pandas").set_index("date").resample("1ME").mean() - 1 df.hvplot.bar(y="Netflix") ``` -------------------------------- ### Get Explorer Settings Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Explorer.ipynb Retrieves a dictionary of the explorer's current customized settings. These settings can be used to re-create the plot using the `.hvplot()` accessor. ```python settings = hvexplorer.settings() settings ``` -------------------------------- ### Grouping by Categories Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api/manual/hvplot.hvPlot.line.ipynb Illustrates how to use the `by` option to visually distinguish categories, automatically coloring lines based on the specified column and returning a HoloViews NdOverlay. ```APIDOC ## hvplot.hvPlot.line with Grouping ### Description Groups and colors lines based on categories in a specified column. ### Method Signature `hvplot.hvPlot.line(by=None, ...)` ### Parameters * **by** (str, optional): Column name to group and color lines by. ### Note The `color` option cannot be used to vectorize coloring each individual line when `by` is used. ### Request Example ```python import hvplot.pandas df = hvplot.sampledata.stocks("pandas").set_index("date").melt(ignore_index=False, var_name="stock") df.hvplot.line(by="stock") ``` ``` -------------------------------- ### Flip X and Y Axes Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/plotting_options/axis.ipynb Use `flip_xaxis` and `flip_yaxis` options to invert the direction of the respective axes. This can change the starting point and direction of value progression. ```python import hvplot.pandas # noqa import pandas as pd df = pd.DataFrame({ "x": list(range(3)), "y": list(range(3)), "v": ["a", "b", "c"], "s": list(range(100, 700, 200)), }) plot_opts = dict( x="x", y="y", color="v", s="s", legend=False, aspect=1, frame_width=200, shared_axes=False, ) ( df.hvplot.scatter(flip_xaxis=False, flip_yaxis=False, title="None", **plot_opts) + df.hvplot.scatter(flip_xaxis=True, flip_yaxis=False, title="flip_xaxis", **plot_opts) + df.hvplot.scatter(flip_xaxis=False, flip_yaxis=True, title="flip_yaxis", **plot_opts) + df.hvplot.scatter(flip_xaxis=True, flip_yaxis=True, title="flip_xaxis + flip_yaxis", **plot_opts) ).cols(2) ``` -------------------------------- ### Control Marker Style with Bokeh and Matplotlib Markers Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api/manual/hvplot.hvPlot.scatter.ipynb Demonstrates controlling marker styles using the `marker` option, showcasing both Bokeh-specific and Matplotlib-compatible markers. Requires importing bokeh and holoviews. ```python import bokeh as bk import holoviews as hv import hvplot.pandas import itertools import pandas as pd bokeh_orig_markers = list(bk.core.enums.MarkerType) hv_bk_mpl_compat_markers = list(hv.plotting.bokeh.styles.markers) print('Bokeh original markers:') print(*map(repr, bokeh_orig_markers), sep=', ', end='\n\n') print('Matplotlib-compatible markers for Bokeh:') print(*map(repr, hv_bk_mpl_compat_markers), sep=', ') df = pd.DataFrame(list(itertools.product(range(6), range(6))), columns=['x', 'y']) df['marker_col'] = bokeh_orig_markers + [''] * (len(df) - len(bokeh_orig_markers)) df.hvplot.scatter( x='x', y='y', marker='marker_col', s=150, title='Bokeh-specific markers' ) * df.assign(y=df.y+0.2).hvplot.labels( x='x', y='y', text='marker_col', text_color='black', text_baseline='bottom', text_font_size='9pt', padding=0.2 ) ``` -------------------------------- ### Plot Xarray Image Source: https://github.com/holoviz/hvplot/blob/main/doc/tutorials/getting_started.ipynb Create an image plot from an Xarray Dataset using hvplot. This example demonstrates setting plot dimensions and disabling dynamic updates. ```python air_ds.hvplot.image(data_aspect=1, frame_width=400, dynamic=False) ``` -------------------------------- ### Build hvPlot Packages Source: https://github.com/holoviz/hvplot/blob/main/doc/developer_guide.md Execute these commands to build both a Python package for PyPI and a Conda package for Anaconda. ```bash pixi run build-pip ``` ```bash pixi run build-conda ``` -------------------------------- ### Create a Grouped Scatter Plot Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Plotting.ipynb Generate a scatter plot grouped by 'passenger_count'. This example samples the data and filters for specific passenger counts to ensure readability. ```python taxi_subset = taxi[taxi.passenger_count.isin([1, 2])].sample(frac=0.001).compute() taxi_subset.hvplot(x='pickup_x', y='pickup_y', by='passenger_count', kind='scatter', alpha=0.6) ``` -------------------------------- ### Plotting Step Charts Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Plotting_with_Plotly.ipynb Create a step chart, similar to a line chart but visualizing discrete steps. The 'where' keyword controls the stepping point, with options 'pre', 'mid' (default), and 'post'. ```python apple_subset.hvplot.step(x='date', y=['high', 'low']) ``` -------------------------------- ### Plotting Interactive Data with Matplotlib Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/Interactive.ipynb Feed the output of chained .interactive method calls into a plot. This example uses a DiscreteSlider to select time and then plots the data. ```python ds.air.interactive.sel(time=pnw.DiscreteSlider).plot() ``` -------------------------------- ### Customizing Step Interpolation with 'where' Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api/manual/hvplot.hvPlot.step.ipynb Demonstrates how to control the step transition point using the 'where' keyword ('pre', 'mid', 'post'). Multiple step plots and a scatter plot are overlaid. ```python import hvplot.pandas # noqa import pandas as pd df = pd.DataFrame({"y": [0, 1, 2]}) df.hvplot.step(where="pre", color="blue", label="pre", alpha=.5) * df.hvplot.step(color="red", label="mid (default)", alpha=.5) * df.hvplot.step(where="post", color="green", label="post", alpha=.5) * df.hvplot.scatter(color="black", padding=0.1) ``` -------------------------------- ### Specifying Colormap in hvPlot Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api_compatibility/pandas/index.ipynb hvPlot allows specifying a colormap locally using the `cmap` argument. This example explicitly sets the colormap to `viridis` for a scatter plot. ```python df.hvplot.scatter('bill_length_mm', 'flipper_length_mm', c=df['body_mass_g'], cmap='viridis') ``` -------------------------------- ### General Plot Styling with Matplotlib Backend Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api_compatibility/pandas/Pandas_API.ipynb Demonstrates basic line plot styling using the 'k--' style argument with the matplotlib backend. ```python ts.plot(style='k--', label='Series', backend='matplotlib'); ``` -------------------------------- ### Default Categorical Colormap in Pandas Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api_compatibility/pandas/index.ipynb Pandas uses a grayscale colormap for categorical data by default. This example plots scatter points colored by a categorical column. ```python categories = list('ABCDEFGHIJLKMNOPQRST') dfc = pd.DataFrame({ 'x': np.random.rand(len(categories)), 'y': np.random.rand(len(categories)), 'category': categories, }) dfc['category'] = dfc['category'].astype('category') dfc.plot.scatter('x', 'y', c='category'); ``` -------------------------------- ### Pandas Scatter Plot Example Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api_compatibility/pandas/index.ipynb Generates a scatter plot using Pandas' plotting API. The `ax` argument, used for overlaying plots, is not supported in hvPlot. ```python plot = df.plot.scatter('bill_length_mm', 'bill_depth_mm', figsize=(4, 3)) ``` -------------------------------- ### Using String and Datashader Reductions for Aggregators Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/plotting_options/resampling.ipynb Demonstrates using both string-based aggregators ('var') and Datashader reduction objects (ds.min('s')) with rasterize. This highlights how different aggregators can visualize different aspects of the data, such as variance or minimum values. ```python import hvplot.pandas import datashader as ds df = hvplot.sampledata.synthetic_clusters("pandas") plot_opts = dict(x='x', y='y', data_aspect=1, frame_height=250) df.hvplot.points( rasterize=True, aggregator='var', color='s', clabel='var(s)', **plot_opts ) + df.hvplot.points( rasterize=True, aggregator=ds.min('s'), clabel='min(s)', **plot_opts ) ``` -------------------------------- ### Create and cumulate time series data Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api_compatibility/pandas/Pandas_API.ipynb Create a pandas Series with a date range index and cumulative random data. This data is used for plotting examples. ```python ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000)) ts = ts.cumsum() ``` -------------------------------- ### Giant Component Setup Source: https://github.com/holoviz/hvplot/blob/main/doc/user_guide/NetworkX.ipynb Sets up parameters for analyzing the giant connected component in a binomial random graph. Includes fallback layout if pygraphviz or pydot are not found. ```python # Copyright (C) 2006-2018 # Aric Hagberg # Dan Schult # Pieter Swart # All rights reserved. # BSD license. # Adapted by Philipp Rudiger import math try: import pygraphviz # noqa from networkx.drawing.nx_agraph import graphviz_layout layout = graphviz_layout except ImportError: try: import pydot # noqa from networkx.drawing.nx_pydot import graphviz_layout layout = graphviz_layout except ImportError: print("PyGraphviz and pydot not found;\n"\ "drawing with spring layout;\n"\ "will be slow.") layout = nx.spring_layout n = 150 # 150 nodes # p value at which giant component (of size log(n) nodes) is expected p_giant = 1.0 / (n - 1) # p value at which graph is expected to become completely connected p_conn = math.log(n) / float(n) ``` -------------------------------- ### Configure Intersphinx Mapping Source: https://github.com/holoviz/hvplot/blob/main/doc/developer_guide.md Extend `intersphinx_mapping` in `conf.py` to enable linking to external documentation. The key is used to reference the site in links. ```python intersphinx_mapping = { 'holoviews': ('https://holoviews.org/', None), } ``` -------------------------------- ### Generate random time series data Source: https://github.com/holoviz/hvplot/blob/main/doc/ref/api_compatibility/pandas/Pandas_API.ipynb Generate a time series of random numbers and set the matplotlib inline backend. This is a setup step for creating plots. ```python %matplotlib inline np.random.seed(123456) ```