I am attempting to create a dataframe histogram and save it as a file.
Here is my code:
ax=df.hist('ColumnName')
fig=ax.get_figure()
fig.savefig('pictureName.png', dpi=100,
bbox_inches='tight')
Run Code Online (Sandbox Code Playgroud)
The first line works fine; however, the second line returns an error: AttributeError: 'numpy.ndarray' object has no attribute 'get_figure'.
Because this question shows the get_figure() being applied to series.hist(), I have also tried using ax=df['ColumnName'].hist(), which successfully produced a histogram but led to the same error message when I attempted to implement get_figure().
正如在这个其他问题中所建议的那样,通常我会跳过get_figure()和fig.savefig(),而不是选择plt.savefig,但我正在制作多个数字.根据我的经验,plt.savefig()在保存多个数字时是不可靠的,而是多次保存一个数字,即使我在每个数字创建和保存后使用fig.close(). …