Python Windrose图例括号格式和

2024-05-13 04:03:27 发布

您现在位置:Python中文网/ 问答频道 /正文

下面我根据this使用Windrose绘制了一个风玫瑰图。首先,图例覆盖了玫瑰的一部分,但是当我试图使用loc来设置它的位置时,图例就消失了。在

其次,图例的右括号是错误的,即[0.0 : 1.0[你知道我该怎么把它改成[0.0 : 1.0]

legend open bracket in place of close

代码:

from windrose import WindroseAxes
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

df = pd.read_csv("C:\2007_GG_wind rose.csv")
ws_SAR = df[' SARwind_10m']
wd_SAR = df['wind direction SAR model_int']
ws_mde = df['gg_mde']
wd_mde = df['wind direction MDE ']

ax=WindroseAxes.from_ax()
ax.bar(wd_SAR,ws_SAR,normed=True, opening=0.8, edgecolor='white')
ax.set_legend()
plt.title("SAR 10m U",y=1.08) #y=1.08 raises the title

Tags: fromimportdfwsmatplotlibascmplt
1条回答
网友
1楼 · 发布于 2024-05-13 04:03:27

复制原件风玫瑰.py从python文件夹到所需的工作目录。以其他方式命名副本,例如windrose_编辑.py. 编辑文件并查找get_labels()函数。我是这样编辑的,但你可以按照你的目的来做。在

def get_labels():
        labels = np.copy(self._info['bins'])
        labels = ["%.1f : %0.1f" %(labels[i], labels[i+1]-0.1) \
                  for i in range(len(labels)-1)]
        return labels

也可以在下面的几行中增加图例的字体大小。在

^{pr2}$

例如,最后导入您编辑过的文件 导入windrose_edit as wind2

和它一起使用

winddir_ = yourdata
windspeed_ = yourdata

fig = plt.figure(figsize=(12, 8), dpi=100, facecolor='w', edgecolor='w')
rect = [0.1, 0.1, 0.8, 0.8]

ax = wind2.WindroseAxes(fig, rect, facecolor='w')

ax.contourf(winddir_, windspeed_, bins=6, normed=True, cmap=cm.RdYlBu_r)
ax.set_legend()

虽然这是一个相对快速和懒惰的解决办法,但并不漂亮

相关问题 更多 >