Я столкнулся с этой странной проблемой при использовании set_major_locator()
, когда использовал подсюжеты, которые имеют разные пределы оси X. Минимальный пример:
import matplotlib.pyplot as pl
import matplotlib.dates as mdates
from datetime import datetime
h24 = mdates.HourLocator(interval=24)
fmt = mdates.DateFormatter('%d-%m %H:%M')
start1 = datetime(year=2016, month=7, day=7, hour=0)
end1 = datetime(year=2016, month=7, day=9, hour=0)
start2 = datetime(year=2016, month=9, day=30, hour=0)
end2 = datetime(year=2016, month=10, day=2, hour=0)
start3 = datetime(year=2016, month=5, day=8, hour=0)
end3 = datetime(year=2016, month=5, day=10, hour=0)
pl.figure(figsize=(9,3))
ax=pl.subplot(131)
ax.set_xlim(start1, end1)
ax.xaxis.set_major_locator(h24)
ax.xaxis.set_major_formatter(fmt)
ax=pl.subplot(132)
ax.set_xlim(start2, end2)
ax.xaxis.set_major_locator(h24)
ax.xaxis.set_major_formatter(fmt)
ax=pl.subplot(133)
ax.set_xlim(start3, end3)
ax.xaxis.set_major_locator(h24)
ax.xaxis.set_major_formatter(fmt)
pl.tight_layout()
Что приводит к:

Если я устанавливаю x-limit всех вспомогательных участков одинаково (используя в этом случае ax.set_xlim(start1, end1)
для всех вспомогательных участков), он работает как ожидалось:

Кроме того, оставление различных set_xlim()
и удаление строк set_major_locator()
и set_major_formatter()
работает (хотя я получаю нечитаемые x-метки в этом случае ..):

Я где-то допускаю глупую ошибку или пропущенные x-tick и метки в моем первом примере - ошибка в Matplotlib?
p.s. Matplotlib 3.0.2, Python 3.7.2