0

I'm trying to plot a signal that lasts 20-30min with 62 samples per second. For visual and research purposes I want the timestamps to scale and change just like the index values do with matplotlib but didn't find a solution to that. After ditching that idea I'm settling for timestamps on the 5 second marks and minor ticks on the second.

I've tried to use .set_minor_locator() but the max ticks it can make is 1000 and I'm dealing with data that would make more than 1000. I saw that plt.xticks() has 'minor=Flase' which should do what I want when True, but no matter my label type this error comes up : AttributeError: 'Text' object has no property 'minor'. I can't find anywhere else where someone has used minor=True. Has anyone else encountered this?

ETray
  • 1
  • 1
  • 2
    Won't those ticks be pretty much invisible if you have a screen with less than 10000 pixels across? Or is that not a concern? – Nick ODell Feb 27 '23 at 18:44
  • I'm trying to use this to inspect the data so I'm zooming in, panning, and taking various screenshots of the same figure. – ETray Feb 27 '23 at 18:51

1 Answers1

0

I've tried to use .set_minor_locator() but the max ticks it can make is 1000

That limit is more of a suggestion than an actual rule. It will warn you if you go above 1K ticks, but it won't stop you.

Here's an example which makes 10000 ticks:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import LinearLocator
x = np.linspace(0, 1, 10)
y = np.linspace(0, 1, 10)
plt.plot(x, y)
ax = plt.gca()

locator = LinearLocator(10000)
ax.xaxis.set_minor_locator(locator)

This shows the following warning:

Locator attempting to generate 10000 ticks ([-0.05, ..., 1.05]), which exceeds Locator.MAXTICKS (1000).

But if you also want it to not show a warning, you can silence it like this.

locator = LinearLocator(10000)
locator.MAXTICKS = 10001  # Must be greater than number of ticks
ax.xaxis.set_minor_locator(locator)

This overrides the value used for the MAXTICKS check. You can do this for any Locator.

Nick ODell
  • 15,465
  • 3
  • 32
  • 66