1
我試圖在x軸上使用日期來繪製一些繪製邊緣,因爲末端的條紋被粘住了。但我不想在軸上使用較大的日期範圍。我嘗試過使用set_xmargin()而沒有運氣。我該如何解決這個問題?繪製x軸的邊緣
import numpy as np
import matplotlib.pyplot as plt
import datetime
import matplotlib.dates as mdates
today = datetime.date.today()
imsiDate = [datetime.date(2016, 1, 11), datetime.date(2016, 1, 14), datetime.date(2016, 1, 18), ]
imsiUp = [13, 6, 24]
imsiDown = [4, 23, 1]
ax = plt.subplot()
ax.set_xmargin(0.75)
ax.xaxis_date()
ax.autoscale_view()
ax.yaxis.grid()
plotUp = ax.bar(imsiDate, imsiUp, width=0.75, color='r', align='center')
plotDown = ax.bar(imsiDate, imsiDown, width=0.75, color='y', align='center', bottom=imsiUp)
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
ax.xaxis.set_minor_locator(mdates.DayLocator())
#limits
t0 = today - datetime.timedelta(7)
t1 = today
ax.set_xbound(t0, t1)
plt.xticks(rotation='vertical')
plt.subplots_adjust(bottom=0.25)
plt.show()