Datums-Ticks und Rotation in Matplotlib

Ich habe ein Problem beim Versuch, meine Datums-Ticks in Matplotlib zu drehen. Ein kleines Beispielprogramm finden Sie weiter unten. Wenn ich versuche, die Häkchen am Ende zu drehen, werden die Häkchen nicht gedreht. Wenn ich versuche, die Häkchen wie unter dem Kommentar "Abstürze" gezeigt zu drehen, stürzt matplot lib ab.

Dies geschieht nur, wenn es sich bei den x-Werten um Datumsangaben handelt. Wenn ich die Variable ersetzedates mit der Variablent im aufruf anavail_plot, dasxticks(rotation=70) Anruf funktioniert gut im Innerenavail_plot.

Irgendwelche Ideen?

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()

Antworten auf die Frage(4)

Ihre Antwort auf die Frage