Add test_axhline in test_datetime.py#27177
Conversation
| birth_date = np.array([datetime.datetime(2020, 4, 10), | ||
| datetime.datetime(2020, 5, 30), | ||
| datetime.datetime(2020, 10, 12), | ||
| datetime.datetime(2020, 11, 15)]) | ||
| year_start = datetime.datetime(2020, 1, 1) | ||
| year_end = datetime.datetime(2020, 12, 31) | ||
| age = [21, 53, 20, 24] | ||
| ax.set_xlabel('Birth Date') | ||
| ax.set_ylabel('Age') | ||
| ax.set_ylim(bottom=year_start, top=year_end) | ||
| ax.bar(x=age, height=birth_date) |
There was a problem hiding this comment.
I would say to keep this even more minimal and not have the bar graph (I think setting the ylim is important here)
If anything, I'd just do a ax.plot, but even that I think is not testing what we are looking to test here.
There was a problem hiding this comment.
That sounds good, thank you for the feedback!
scottshambaugh
left a comment
There was a problem hiding this comment.
Could you add subplots to test different combinations of numbers and datetimes on different axes? Similar to the test you added here: #27084
|
@CozyFrog ah I mean having subplots where the X/Y data are different combinations of datetime vs numbers. Right now you have datetimes on the Y axis with numbers on the X axis, and adding the other permutations of that should exercise these codepaths more fully (I think). Your other PR did this well. |
|
@scottshambaugh I don't think that actually makes sense for this method, honestly... the x axis values are in |
|
I'll defer to you on that @ksunden, I'm admittedly not super familiar with how the code paths for the coordinate transforms work work. If it's drawn directly in axes coordinates they I think you're right, my thought was if the xrange was cast to the data coordinates before being drawn. |
|
Thank you for the discussion @scottshambaugh & @ksunden – how should I move forward with this PR? Does this require any modifications? |
|
Yes, the X values are drawn directly in axes coordinates, and in fact the method explicitly checks that those values do not have units and prevents passing an alternate transform even. Thus I think we should be good to go here, though we do have a 2-reviewer policy for non-doc changes (And I was the first approver, soo). |


PR summary
I have added a datetime (no timedelta; this function does not support it, and I believe that is correct) smoke test for
Axes.axhlineinlib/matplotlib/test/test_datetime.py.This addresses the
Axes.axhlinetask from #26864.The image below is the plot generated from my example code.

PR checklist