timhoffm on v3.5.x
Backport PR #21864: Delete "Loa… Merge pull request #21865 from … (compare)
jklymak on main
Delete "Load converter" example… Merge pull request #21864 from … (compare)
Folks, I am not sure it can actually be considered as a bug but I find the behavior of
IndexLocator quite surprising when it is coupled to a plot drawn with
eventplot. For example, the following script
import numpy as np import matplotlib.pyplot as plt from matplotlib.ticker import IndexLocator # Event sequence is "10" at 0.1 s, "21" at 0.5 s, and "10" at 0.9 s. events = [[0.1, 0.9], [0.5]] indices = [10, 21] event_height = 0.9 # not 1 to better visualize rows of events fig, axs = plt.subplots(ncols=2, num='eventplot_and_IndexLocator') for ax in axs: ax.eventplot(events, lineoffsets=indices, linelengths=event_height) # One wants the ticks to be all the indices: a possible thought may # be to use an IndexLocator with base = 1 and offset = 0: axs.yaxis.set_major_locator(IndexLocator(1, 0)) # Issue 1?: the tick values are not integers... # Case that is even worse: let's assume that for any good reason, we want # the ticks to start at 12 (offset = 12), and go 5 by 5 (base = 5). axs.yaxis.set_major_locator(IndexLocator(5, 12)) # Issue 2?: one would expect the ticks to be 12, 17 and 21... plt.tight_layout() # for eyes' pleasure plt.show()
produces the image above.
MultipleLocatorcan be a working solution. However, it does not seem to provide the possibility to use an offset as
IndexLocatorfor a while before realizing that
MultipleLocatoralready implement (and in a better way ^^) most of what I was trying to achieve (through a
Baseclass). So I would agree that “just” adding an
MultipleLocatorseems a more appealing solution :). For the record, from what I understood, one of the reason to my
IndexLocatorproblem is that this locator uses the “data limit” to work with (BTW, why rely on the data limits and not the view ones?), which does not return integer values in the case of an
linelengths != 1. Another part of the issue is that the the way the offset is handled does not take into account the case where
offset >= base.
MultipleLocator(easier than what I was trying to do with
IndexLocator… => ~ 3 slocs). I'll try to send an email (maybe only this weekend) about this on the mailing-list, hoping for Eric's attention. We'll see if it is worth a PR and maybe what to do with
IndexLocator(, which appears to be a very old piece of the codebase).