I had a problem with my date captions being rotated in matplotlib. The following is a small sample program. If I try to rotate the tics at the end, the tics will not rotate. If I try to rotate ticks, as shown in the 'crashes' comments, then matplot lib will work.
This only happens if the x values โโare dates. If I replace the dates variable with the t variable when calling avail_plot , calling xticks(rotation=70) works fine inside avail_plot .
Any ideas?
import numpy as np import matplotlib.pyplot as plt import datetime as dt def avail_plot(ax, x, y, label, lcolor): ax.plot(x,y,'b') ax.set_ylabel(label, rotation='horizontal', color=lcolor) ax.get_yaxis().set_ticks([]) #crashes #plt.xticks(rotation=70) ax2 = ax.twinx() ax2.plot(x, [1 for a in y], 'b') ax2.get_yaxis().set_ticks([]) ax2.set_ylabel('testing') f, axs = plt.subplots(2, sharex=True, sharey=True) t = np.arange(0.01, 5, 1) s1 = np.exp(t) start = dt.datetime.now() dates=[] for val in t: next_val = start + dt.timedelta(0,val) dates.append(next_val) start = next_val avail_plot(axs[0], dates, s1, 'testing', 'green') avail_plot(axs[1], dates, s1, 'testing2', 'red') plt.subplots_adjust(hspace=0, bottom=0.3) plt.yticks([0.5,],("","")) #doesn't crash, but does not rotate the xticks #plt.xticks(rotation=70) plt.show()
python matplotlib
Neal Jun 29 2018-12-12T00: 00Z
source share