【发布时间】:2015-08-02 02:03:07
【问题描述】:
我有一个 Python 脚本,我想用它来学习 iPython Notebook,但在文本中显示图表时遇到了问题。
这是我正在使用的部分代码。
#import baseline and iteration files
df_final = pd.read_csv(os.path.join(CSV_dir, 'mean_prop_iter.csv'))
baseline = pd.read_csv(os.path.join(CSV_dir, 'mean_prop_base.csv'))
## create base figure
fig = plt.figure()
ax1 = fig.add_subplot(111)
## create histogram
df_final['iter_prop_in'].hist(bins=[0.5, 0.51, 0.52, 0.53, 0.54,
0.55, 0.56, 0.57, 0.58, 0.59, 0.60],
rwidth=1.0, align='mid', facecolor='red')
此时一切看起来都很好。
我随后的命令不是我所期望的。
## define x-axis limits
label_range = np.arange(0.0, 1.1, 0.1)
labels = ax1.set_xticks(label_range)
## turn off ticks along the top and right axes
plt.tick_params(axis='both', top='off', right='off', direction='out')
这里正确显示了新的 x 轴范围,但未显示直方图。 y 轴刻度限制也变为 0 到 1,这是我没想到的。
如果我在 Python 2.7 (Anaconda Spyder) 中运行相同的命令,直方图将按预期显示。
我做错了什么?
【问题讨论】:
标签: matplotlib graph ipython-notebook