I'm currently tracking my internet speed and want to generate a plot of my measurements with a Timestamp, Upload value and Download value.
I'm using this to create the plot
df.plot(
kind='line',
x=timestamp_column_name,
y=[download_column_name, upload_column_name],
figsize=(12,5)
)
Generated plot:
Now I would like to add a line to this plot with the constant height of y=100000
but I can't figure out how to do this correctly. How should I do this with Pandas?
You can plot a vertical line in matplotlib python by either using the plot() function and giving a vector of the same values as the y-axis value-list or by using the axvline() function of matplotlib. pyplot that accepts only the constant x value. You can also use the vlines() function of the matplotlib.
To create a time series plot, we can use simply apply plot function on time series object and if we want to create a vertical line on that plot then abline function will be used with v argument.
You can use axhline
. Since df.plot()
is a wrapper for matplotlib and returns the Matplotlib axes, which contain all the methods for interacting with the plot, it can be used straight forward as:
ax = df.plot( ... )
ax.axhline(y=100000)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With