How to Plot Lines with Markers#

This guide shows you how to draw a line with a marker on each data point. hvPlot has no single option for this: you overlay a line plot and a scatter plot. The approach works with all plotting extensions.

import hvplot.pandas  # noqa

stocks = hvplot.sampledata.stocks("pandas")
last_weeks = stocks.iloc[-20:]  # weekly data

Overlay a line and a scatter plot#

Create the line and the scatter plot from the same arguments and combine them with *. Use y=[...] or by and the colors of the line and its markers match.

options = dict(x='date', y=['Apple', 'Google'], width=600, height=300)

last_weeks.hvplot.line(**options) * last_weeks.hvplot.scatter(**options)

Style the scatter plot independently of the line. Use marker to set the shape ('s' for squares) and size to set its size.

line = last_weeks.hvplot.line(x='date', y='Apple', width=600, height=300)
points = last_weeks.hvplot.scatter(x='date', y='Apple', marker='s', size=60)

line * points

Next Steps

This web page was generated from a Jupyter notebook and not all interactivity will work on this website.