Matplotlib's Cursor Info Seems To Be Dependant From Tick Resolution - How Can I Change This Dependancy
With matplotlib, how can I see the exact value of the cursor for date values at the bottom right of the interactive plot? It seems, that this is dependent from the tick resolution
Solution 1:
In order to format the x coordinate for datetime axes differently than the actual format used on the axes, you can set the Axes.fmt_xdata
attribute to a callable that takes the position in and outputs the desired string.
In this case,
ax.fmt_xdata = lambda x: matplotlib.dates.num2date(x).strftime("%Y-%m-%d")
Example:
from datetime import datetime
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
plt.plot([datetime.now(), datetime(2020,6,6)], [1,2], "-o")
plt.gca().fmt_xdata = lambda x: mdates.num2date(x).strftime("%Y-%m-%d")
plt.show()
Post a Comment for "Matplotlib's Cursor Info Seems To Be Dependant From Tick Resolution - How Can I Change This Dependancy"