use*_*869 4 numpy matplotlib python-2.7 pandas
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().
我非常希望尽可能整齐地解决这个问题,这样我就可以顺利地将解决方案带到其他应用程序中,而不必每次必须使用不同的管道磁带修复程序.
谢谢您的帮助!
你能试试下面的代码吗?
import pandas as pd
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
df.hist('ColumnName', ax=ax)
fig.savefig('example.png')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4664 次 |
| 最近记录: |