You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Having thousands of categories is most likely a sign that the user
forgot to convert strings to floats or dates, but we may as well not
take forever to generate the incorrect plot so that they can observe the
failure faster.
Right now StrCategoryFormatter constructs the value-to-label dict at
every call to `__call__` which leads to quadratic complexity when
iterating over the ticks. Instead, just do this once in `format_ticks`
(and let `__call__` use that implementation too), for linear complexity.
This speeds up
from pylab import *
cats = [str(x) for x in np.random.rand(4000)] # Bunch of labels.
plt.plot(cats)
plt.gcf().canvas.draw()
from ~25s to ~11s (and the difference gets bigger for more ticks as
we're comparing O(n^2) to O(n) (modulo dict lookup terms in log(n),
probably)).
The other option was to make UnitData maintain both a forward and a
backward mapping in sync but this would require passing the UnitData
instance rather than the mapping to the StrCategoryFormatter constructor
and the API break is just not worth it.
0 commit comments