我使用windrose模块https://windrose.readthedocs.io/en/latest/index.html绘制了我的风向数据(方向和速度)。结果看起来不错,但我不能将它们导出为图形(png、eps或任何一开始的图形),因为结果是一个没有'savefig‘属性的特殊对象类型,或者我找不到它。
我有两个pandas.core.series.Series: ff,dd
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'你知道如何从结果中创建图形,以便我可以在工作中使用它吗?
谢谢!
发布于 2020-10-25 10:43:47
我们可以使用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')发布于 2021-09-30 08:45:59
假设你使用的是box类型的windrose模块。然后,下面的代码将您的wind rose转换为图像:
ax = WindroseAxes.from_ax()
ax.box(direction=wd, var=ws, bins=bins)
buff = io.BytesIO()
plt.savefig(buff, format="jpeg")
pixmap = QtGui.QPixmap()
pixmap.loadFromData(buff.getvalue())
dialog.ui.windrose_label.setScaledContents(True)
dialog.ui.windrose_label.setPixmap(pixmap)发布于 2019-01-08 02:09:08
发生错误是因为您正在尝试保存子图而不是图形。尝试:
fig,ax2 = plt.subplots(1,1) # Or whatever you need.
# The windrose code you showed
fig.savefig('./figures/windrose.png')https://stackoverflow.com/questions/54079464
复制相似问题