I am looking to plot a irregular time series with a line shape that connects the data points vertically to the x-axis (with no lines connecting the data points themselves). Sort of like the ACF plots in R, except with irregular time points:
This is not covered by the 6 available line shapes (https://plotly.com/python/line-charts/#interpolation-with-line-plots). Is it possible with Plotly? Do we have a clever work-around for this?
to my knowledge there is no available shape to do what you want, but you can create it yourself by making the y-values passing zero every time, like this, for example:
import plotly.express as px
import numpy as np
df = px.data.iris()
data = df.sepal_length
x = data.index.values
y = data.values
def create_stem_data(x,y, baseline=0.):
'''makes y data passing 0 before inbetween actual value to create data for a stem plot
x,y are 3 times the original length
x,y = create_stem_data(x,y)
fig = px.line(x=x,y=y)
hope this helps, Alex-
You can also accomplish this with bar charts with a very narrow bar width.
Thank you for the suggestion!
The only downside is the zeros being visible in plot and on hover. But I slightly prefer this solution over bar charts which Nicholas suggested above.
Is there an updated way to produce such a plot with plotly ?
What I would like to obtain is a something like a stem plot in matplotlib.
Using a bar plot with narrow width is not so satisfactory because I have 14000 points and if you zoom in, consecutive bars overlap. The width of the bar may depend on the zoom level.
Adding zero is an option but it leads to 3 times the amount of data.
Thank you for you help.