将python-windrose绘图导出为eps
我用windrose模块绘制了我的风数据(方向和速度)。 结果看起来不错,但我无法将它们导出为图形(png、eps或任何开始的图形),因为结果是一种特殊的对象类型,没有“savefig”属性,或者我找不到它 我有两只熊猫将python-windrose绘图导出为eps,python,plot,save,Python,Plot,Save,我用windrose模块绘制了我的风数据(方向和速度)。 结果看起来不错,但我无法将它们导出为图形(png、eps或任何开始的图形),因为结果是一种特殊的对象类型,没有“savefig”属性,或者我找不到它 我有两只熊猫 print(ff) 结果: TIMESTAMP 2016-08-01 00:00:00 1.643 2016-08-01 01:00:00 2.702 2016-08-01 02:00:00 1.681 2016-08-01 03:00:00 2.2
print(ff)
结果:
TIMESTAMP
2016-08-01 00:00:00 1.643
2016-08-01 01:00:00 2.702
2016-08-01 02:00:00 1.681
2016-08-01 03:00:00 2.208
....
print(dd)
结果:
TIMESTAMP
2016-08-01 00:00:00 328.80
2016-08-01 01:00:00 299.60
2016-08-01 02:00:00 306.90
2016-08-01 03:00:00 288.60
...
我的代码如下所示:
from windrose import WindroseAxes
ax2 = WindroseAxes.from_ax()
ax2.bar(dd, ff, normed=True, opening=0.8, edgecolor='white', bins = [0,4,11,17])
ax2.set_legend()
ax2.tick_params(labelsize=18)
ax2.set_legend(loc='center', bbox_to_anchor=(0.05, 0.005), fontsize = 18)
ax2.savefig('./figures/windrose.eps')
ax2.savefig('./figures/windrose.png')
但结果是:
AttributeError: 'WindroseAxes' object has no attribute 'savefig'
你知道如何根据结果创建一个数字,以便我可以在工作中使用它吗
谢谢 发生错误是因为您试图保存子批次而不是图形。请尝试:
fig,ax2 = plt.subplots(1,1) # Or whatever you need.
# The windrose code you showed
fig.savefig('./figures/windrose.png')
我们可以使用
matplotlib
中的pyplot.savefig()
import pandas as pd
import numpy as np
from windrose import WindroseAxes
from matplotlib import pyplot as plt
from IPython.display import Image
df_ws = pd.read_csv('WindData.csv')
# df_ws has `Wind Direction` and `Wind Speed`
ax = WindroseAxes.from_ax()
ax.bar(df_ws['Wind Direction'], df_ws['Wind Speed'])
ax.set_legend()
# savefig() supports eps, jpeg, jpg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff
plt.savefig('WindRose.jpg')
plt.close()
Image(filename='WindRose.jpg')
是的,这是一个开始。但现在我把风玫瑰图覆盖在一个正方形的空图上。。。我的代码是相同的,只添加了行:fig,ax2=plt.子批(1,1),并将行:ax2=WindroseAxes.from_ax()更改为ax2=WindroseAxes.from_ax(fig=fig)。。我还尝试了ax2=WindroseAxes.from_ax(ax=ax2),但后来我得到了一个AttributeError:Unknown属性normed。。。如果我从ax2.bar(..)中删除“normed”属性,我将获得AttributeError:Unknown属性打开。。。