我正在编辑我的图一步一步。这样做,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