3
下面是一個小小的片段,說明我與從matplotlib在Axes3D實例中使用的多維數據集的大小以及切斷軸標籤有關的問題。雖然我可以很容易地更改圖形畫布的背景顏色,但仍然會導致位於標籤上的文本變形。有沒有人有想法如何最好地改變用於繪製數據的3D盒子的實際尺寸?簡單地改變子圖尺寸似乎沒有幫助。這種行爲最好通過運行代碼來說明。繪製完成後,日期格式的文字顏色發生變化,一端變得稍暗。任何幫助表示讚賞。Axes3D數據標籤和繪圖限制
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.dates as dates
import datetime, random
import matplotlib.ticker as ticker
def random_date():
date = datetime.date(2008, 12,01)
while 1:
date += datetime.timedelta(days=30)
yield (date)
def format_date(x, pos=None):
return dates.num2date(x).strftime('%Y-%m-%d') #use FuncFormatter to format dates
r_d = random_date()
some_dates = [dates.date2num(r_d.next()) for i in range(0,20)]
fig = plt.figure(facecolor = 'k')
ax = fig.add_subplot(111, projection='3d')
fig.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9)
for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]):
xs = np.array(some_dates)
ys = np.random.rand(20)
ax.bar(xs, ys, zs=z, zdir='y', color=c, alpha=0.8,width=8)
ax.w_xaxis.set_major_locator(ticker.FixedLocator(some_dates)) # I want all the dates on my xaxis
ax.w_xaxis.set_major_formatter(ticker.FuncFormatter(format_date))
for tl in ax.w_xaxis.get_ticklabels(): # re-create what autofmt_xdate but with w_xaxis
tl.set_ha('right')
tl.set_rotation(30)
ax.set_ylabel('Series')
ax.set_zlabel('Amount')
plt.show()