【问题标题】:Python Windrose legend bracket format and locPython Windrose 图例括号格式和位置
【发布时间】:2016-10-13 15:13:40
【问题描述】:

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

其次,图例右括号是错误的,即 [0.0 : 1.0[ 知道如何将其修复为 [0.0 : 1.0]

代码:

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

【问题讨论】:

  • 我认为括号格式是正常的。右括号只是表示区间中不包含上位值
  • 我以前从未见过,但这是有道理的,谢谢
  • @Tryph 你知道从图例中删除括号的方法吗?
  • 不幸的是没有。我从未使用过 matplotlib 或 windrose

标签: python matplotlib windrose


【解决方案1】:

将原始的 windrose.py 从你的 python 文件夹复制到你想要的工作目录。以其他方式命名副本,例如windrose_edit.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

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

def set_legend(self):
    l = self.legend(borderaxespad=-0.10)
    plt.setp(l.get_texts(), fontsize=12)

最后导入您编辑的文件,例如 将 windrose_edit 导入为 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()

虽然是一种相对快速和懒惰的解决方法,但它并不漂亮

【讨论】:

    猜你喜欢
    • 2019-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多