我正在編輯我的圖一步一步。這樣做,plt
功能從matplotlib.pyplot
立即適用於我的圖形輸出的pylab。那很棒。爲什麼pyplot方法立即適用,子圖軸方法不適用?
如果我處理一個子圖的座標軸,它就不會再發生了。 請在我最小的工作示例中找到兩個替代方案。
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
f = plt.figure()
sp1 = f.add_subplot(1,1,1)
f.show()
# This works well
sp1.set_xlim([1,5])
# Now I plot the graph
df = pd.Series([0,5,9,10,15])
df.hist(bins=50, color="red", alpha=0.5, normed=True, ax=sp1)
# ... and try to change the ticks of the x-axis
sp1.set_xticks(np.arange(1, 15, 1))
# Unfortunately, it does not result in an instant change
# because my plot has already been drawn.
# If I wanted to use the code above,
# I would have to execute him before drawing the graph.
# Therefore, I have to use this function:
plt.xticks(np.arange(1, 15, 1))
我明白,有matplotlib.pyplot
和axis
實例之間的差異。我錯過任何東西還是隻是這樣工作?
'show'阻塞,當我從python使用它。它不會阻止ipython,但我想是由於我的設置。和'f.show()'就足夠了 –
+1爲背景信息 – Xiphias