-
Notifications
You must be signed in to change notification settings - Fork 28
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
Fix xvals for datetime axis #210
base: main
Are you sure you want to change the base?
Conversation
0e20efd
to
0e9e344
Compare
01afff0
to
5ec1ace
Compare
Now that CI is updated I'm able to update the image test, so this PR is good to go. Would still appreciate some docs/pointers on how to get the image tests running locally! |
I'll note that while I didn't want to add pandas as a dependency, this does work for pandas timestamps as well. Here was my local test script: import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from labellines import labelLines, labelLine
x = np.linspace(0, 10, 100)
t = pd.date_range(start='2020-01-01', periods=100) # Creates a DatetimeIndex
df = pd.DataFrame({'x': x, 't': t})
fig, ax = plt.subplots()
ax.plot(df['t'], df['x'], label='x')
ax.plot(df['t'], df['x'] + 1, label='x')
labelLines(ax.get_lines(), zorder=2.5, xvals=[df['t'].iloc[0], df['t'].iloc[-1]]) # df['t'].iloc[-1] is a pandas Timestamp
plt.show(block=True)
fig, ax = plt.subplots()
datetimes = pd.to_datetime(df['t']).values # Creates a numpy array with dtype np.datetime64
ax.plot(datetimes, df['x'], label='x')
labelLine(ax.get_lines()[0], x=datetimes[-1])
plt.show(block=True) |
The easy™ solution is to run on the CI and the "correct" version will appear in the artefacts of the build which you can download and add to your PR in hindsight. |
@@ -164,7 +164,7 @@ def test_dateaxis_advanced(setup_mpl): | |||
ax.xaxis.set_major_locator(DayLocator()) | |||
ax.xaxis.set_major_formatter(DateFormatter("%Y-%m-%d")) | |||
|
|||
labelLines(ax.get_lines()) | |||
labelLines(ax.get_lines(), xvals=(dates[0], dates[-1])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this place the first label on 2018/11/01 and the second on 2018/11/03?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true for a list input xvals=[dates[0], dates[-1]]
, but the tuple input adds padding equivalent to a blank label at the extremes automatically
Closes #208
@cphyc do you have setup instructions for the image comparison tests? I cannot get them to fail if I change them.