一旦你開始使用matplotlib面向對象模型更多的時候,你就可以到軸的所有相關參數作爲關鍵字添加到使這些功能軸。
一個簡單的例子:
fig = plt.figure()
ax = fig.add_subplot(111, xlabel="time", ylabel="money")
較長的例子:
fig1 = plt.figure(figsize=(10,8))
ax1 = fig1.add_axes((0.1, 0.1, 0.8, 0.8), # full positional control
frameon=True, # display frame boundary
aspect='equal', # set aspect ratio upon creation
adjustable='box', # what part of the axes can change to meet the aspect ratio requirement?
xticks=[0.1, 1.2, 10],
xlabel='voltage (V)',
xlim=(0.05, 10.05),
yticks=[0, 10],
ylabel='current (µA)',
ylim=(0, 2))
上接收到的意見之後,您還可以使用「屬性批處理器」 ax.set
,這是的漂亮的小matplotlib便利功能。
plt.close('all')
plt.plot([1,2,3], [4, 7, 1])
plt.gca().set(xlabel='x', ylabel='y')
你的代碼(或者你)是否真的患上了這兩行? – Chiel