generated at
axis.twinx()でコピーした軸のset_tickxlabels()をするとコピー元のlabelも消える
axis.twinx()でコピーした軸の set_tickxlabels([]) をするとコピー元のlabelも消える
py
import numpy as np import matplotlib.pyplot as plt import datetime x = [datetime.datetime(2011, 12, 1, 10, 0), datetime.datetime(2011, 12, 1, 11, 0), datetime.datetime(2011, 12, 1, 12, 0)] y = [4, 0, 2] fig, ax = plt.subplots() ax.xaxis_date() ax.xaxis.set_major_formatter(mdates.DateFormatter("%H:%M")) ax.bar(x, y, width = 0.001, color='C0') # ## 累積和を描画 ax2 = ax.twinx() y2 = [8, 1, 4] ax2.plot(x, y2, color='C1') ax2.grid(False) # どちらをコメントアウトしても両方のx軸のラベルが消える # ax2.xaxis.set_ticklabels([]) # ax.xaxis.set_ticklabels([])