-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[ENH]: matplotlib.pyplot.axvline does not support datetime for xmin/xmax #28612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The same error would occur with |
I know that it doesn't work currently -- that is why it's a feature request. It appears very odd that I can easily specify my vertical line on a data coordinate, but if I want to specify the start and end points of a horizontal line, I can no longer use data coordinates. |
There is no difference between
|
To use axhline effectively with dates on the x-axis, you'll need to simulate a horizontal line across a range of dates by combining axhline with ax.set_xlim( ). Since axhline doesn't directly support date ranges for xmin and xmax, you use axhline to draw the line at a specific y-value and then adjust the x-axis limits to ensure that the horizontal line spans the desired range of dates. Here’s how to do it:
|
As mentioned above, Action: The documentation should be improved axhline reads "Add a horizontal line across the Axes", which is technically correct, but it's not obvious that it's not for data coordinates. We should make this more clear. |
You're correct that axhline is designed to work with axes units rather than data units, which can be a bit confusing when you want to place a horizontal line based on specific data points on the x-axis. Summary
|
Problem
I am trying to create a figure with dates on the x-axis.
Matplotlib already supports entering datetime as x-coordinate for vertical lines:
ax.axvline(dt)
But it does not allow me to use datetimes as xmin and xmax for horizontal lines:
Proposed solution
No response
The text was updated successfully, but these errors were encountered: