I am plotting dates and times on the x axis in matplotlib. Because I want to plot as many labels as possible, I am using newlines in the x labels like so:
Unfortunately, this has the side effect of resizing the matplotlib window when I hover over the graph since it tries to print the x value, which contains the newlines, at the bottom. See this video here as a demonstration:
CodePudding user response:
I don't want to get rid of the toolbar, but I just need it to not print the x point in the bottom right corner (which is what's causing the window to resize).
You can monkeypatch ax.format_coord
to display a differently formatted string for a given x, y value (or None as below).
fig, ax = plt.subplots()
ax.format_coord = lambda x, y : '' # don't display anything
plt.show()
This is scope creep but if you want to modify the string of the original ax.format_coord
, then you have to wrap the original function:
fig, ax = plt.subplots()
old_function = ax.format_coord
ax.format_coord = lambda x, y: old_function(x, y) "some random nonsense"
plt.show()