matplotlib-label-lines
matplotlib-label-lines copied to clipboard
Fix xvals for datetime axis
Closes https://github.com/cphyc/matplotlib-label-lines/issues/208
@cphyc do you have setup instructions for the image comparison tests? I cannot get them to fail if I change them.
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.
Hey @cphyc, any plans for a point release soon? Would love to use the recent PRs :)
v0.8.1 is fresh from the oven (https://pypi.org/project/matplotlib-label-lines/)!
Awesome, ty!