6

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: enter image description here

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?

1 Answer 1

18

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)
Sign up to request clarification or add additional context in comments.

1 Comment

I guess it would be useful to mention what's going on, namely that df.plot() returns the Matplotlib axes, which contain all the methods for interacting with the plot. After that ax.axhline() seems pretty self explanatory!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.