hvPlot.points#
- hvPlot.points(x=None, y=None, **kwds)[source]#
A points plot visualizes positions in a 2D space. This is useful for example for geographic plots.
Although the
hvplot.hvPlot.scatter()
plot is superficially similar to thepoints
plot (they can generate plots that look identical), the two plot types are semantically quite different. The fundamental difference is thatscatter
is used to visualize data where the y variable is dependent, unlikepoints
.This difference means that
points
plots can most naturally overlay with other plots that express independent variables in two-dimensional space, such as raster types likehvplot.hvPlot.image()
. Conversely,scatter
expresses a dependent relationship between x and y and thus most naturally overlay with chart types such ashvplot.hvPlot.line()
.Reference: https://hvplot.holoviz.org/ref/api/manual/hvplot.hvPlot.points.html
Plotting options: https://hvplot.holoviz.org/ref/plotting_options/index.html
- Parameters:
- xstring, optional
The coordinate variable along the x-axis. Default is the first numeric field.
- ystring, optional
The coordinate variable along the y-axis. Default is the second numeric field.
- cstring, optional
The dimension to color the points by
- sint, optional, also available as ‘size’
The size of the marker
- markerstring, optional
The marker shape specified above can be any supported by matplotlib, e.g. s, d, o etc. See https://matplotlib.org/stable/api/markers_api.html.
- scale: number, optional
Scaling factor to apply to point scaling. Default is 1.
- logzbool
Whether to apply log scaling to the z-axis. Default is False.
- **kwdsoptional
Additional keywords arguments are documented in Plotting Options. Run
hvplot.help('points')
for the full method documentation.
- Returns:
holoviews.element.Points
/ Panel objectYou can print the object to study its composition and run:
import holoviews as hv hv.help(the_holoviews_object)
to learn more about its parameters and options.
References
Backend-specific styling options#
alpha, angle, cmap, color, fill_alpha, fill_color, hit_dilation, hover_alpha, hover_color, hover_fill_alpha, hover_fill_color, hover_line_alpha, hover_line_cap, hover_line_color, hover_line_dash, hover_line_dash_offset, hover_line_join, hover_line_width, line_alpha, line_cap, line_color, line_dash, line_dash_offset, line_join, line_width, marker, muted, muted_alpha, muted_color, muted_fill_alpha, muted_fill_color, muted_line_alpha, muted_line_cap, muted_line_color, muted_line_dash, muted_line_dash_offset, muted_line_join, muted_line_width, nonselection_alpha, nonselection_color, nonselection_fill_alpha, nonselection_fill_color, nonselection_line_alpha, nonselection_line_cap, nonselection_line_color, nonselection_line_dash, nonselection_line_dash_offset, nonselection_line_join, nonselection_line_width, palette, radius, radius_dimension, selection_alpha, selection_color, selection_fill_alpha, selection_fill_color, selection_line_alpha, selection_line_cap, selection_line_color, selection_line_dash, selection_line_dash_offset, selection_line_join, selection_line_width, size, visible
alpha, c, cmap, color, ec, ecolor, edgecolor, edgecolors, facecolors, linewidth, lw, marker, norm, s, visible, vmax, vmin
Examples#
Basic points plot#
This example shows how to create a simple points plot.
import hvplot.pandas # noqa
import pandas as pd
df = pd.DataFrame({"x": [0, 1, 2, 3], "y": [0, 1, 4, 9]})
df.hvplot.points(x="x", y="y")
Let’s use a more realistic dataset.
import hvplot.pandas # noqa
df = hvplot.sampledata.earthquakes("pandas")
df.hvplot.points(x='lon', y='lat', title='Earthquakes location')
Grouping by categories#
To distinguish categories visually, you can use the by
parameter. This automatically colors points based on the specified column.
import hvplot.pandas # noqa
df = hvplot.sampledata.earthquakes("pandas")
df.hvplot.points(
x='lon', y='lat', marker='s',
by=['depth_class', 'mag_class'], title='Points plot colored by depth and magnitude classes',
)
Grouping by categories#
To distinguish categories visually, you can use the by
parameter. This automatically colors points based on the specified column(s). The generated plot is a HoloViews NdOverlay.
import hvplot.pandas # noqa
df = hvplot.sampledata.earthquakes("pandas")
df.hvplot.points(
x='lon', y='lat', by=['depth_class', 'mag_class'],
title='Points plot grouped by depth and magnitude classes with "by"',
)
Note
If your goal is to simply color the plot by a given categorical variable, then you can use the color
option instead of by
. The former will vectorize the color styling (i.e., each marker has its own color) while the latter will generate an overlay of points plots. As a consequence, using color
is much more efficient in this case.
import hvplot.pandas # noqa
df = hvplot.sampledata.earthquakes("pandas")
df.hvplot.points(
x='lon', y='lat', color='depth_class',
title='Points plot colored by depth class with "color"',
)
Control marker style#
The marker
keyword can be used to control the markers style, see the scatter
reference page for more information.
Control color and size#
You can also vary marker size with the s
option and color with c
(or color
) using numeric columns.
import hvplot.pandas # noqa
df = hvplot.sampledata.earthquakes("pandas")
df.hvplot.points(
x="lon", y="lat", c="mag", s="depth", cmap="inferno_r",
clabel="Magnitude values", title="Earthquake depth (color by magnitude)",
)
Scatter plot with scaling and logarithmic color mapping#
This example shows how to fine-tune scatter plots by scaling point sizes and applying a logarithmic color scale. Note we set the scale
option to uniformally increase the marker size by a factor of 3.
import pandas as pd
import hvplot.pandas # noqa
import numpy as np
df = pd.DataFrame({
'x': np.random.rand(100) * 10,
'y': np.random.rand(100) * 10,
'size': np.random.rand(100) * 100 + 10,
'intensity': np.random.lognormal(mean=2, sigma=1, size=100)
})
df.hvplot.points(
x='x', y='y', s='size', scale=3,
c='intensity', cmap='Blues', logz=True,
title='Points plot with size scaling and log color'
)
Geographic plot#
points
plots are 2D plots and well suited for displaying maps. In this example we set geo=True
to enable plotting with GeoViews and tiles=True
to overlay the points on web map tiles.
import hvplot.pandas # noqa
df = hvplot.sampledata.earthquakes("pandas")
df.hvplot.points(
x="lon", y="lat", c="mag", s="depth", cmap="inferno_r",
clabel="Magnitude values", title="Earthquake depth (color by magnitude)",
geo=True, tiles=True,
)
Geographic plot with GeoPandas#
import geopandas as gpd
import hvplot.pandas # noqa
data = {
'City': ['London', 'Paris', 'Berlin', 'Madrid', 'Rome', 'Vienna', 'Warsaw', 'Amsterdam'],
'Country': ['United Kingdom', 'France', 'Germany', 'Spain', 'Italy', 'Austria', 'Poland', 'Netherlands'],
'Latitude': [51.5074, 48.8566, 52.5200, 40.4168, 41.9028, 48.2082, 52.2297, 52.3676],
'Longitude': [-0.1278, 2.3522, 13.4050, -3.7038, 12.4964, 16.3738, 21.0122, 4.9041]
}
cities = gpd.GeoDataFrame(
data,
geometry=gpd.points_from_xy(data['Longitude'], data['Latitude']),
crs="EPSG:4326",
)
cities.hvplot.points(geo=True, tiles=True)