Python Windrose图例括号格式和位置 [英] Python Windrose legend bracket format and loc

查看:72
本文介绍了Python Windrose图例括号格式和位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下,我根据

代码:

 从windrose导入WindroseAxes将cmplotlib.cm导入为cm导入matplotlib.pyplot作为plt将numpy导入为np将熊猫作为pd导入df = pd.read_csv("C:\2007_GG_wind 玫瑰.csv")ws_SAR = df ['SARwind_10m']wd_SAR = df['风向SAR model_int']ws_mde = df['gg_mde']wd_mde = df['风向 MDE']ax=WindroseAxes.from_ax()ax.bar(wd_SAR,ws_SAR,normed = True,开口= 0.8,edgecolor ='white')ax.set_legend()plt.title("SAR 10m U",y=1.08) #y=1.08 提升标题

解决方案

将原始 windrose.py 从您的 python 文件夹复制到您想要的工作目录.以其他方式命名副本,例如windrose_edit.py.编辑文件并查找 get_labels() 函数.我是这样编辑的,但你可以根据自己的目的采用它.

  def get_labels():标签 = np.copy(self._info['bins'])标签= [%.1f:%0.1f"%(标签[i],标签[i + 1] -0.1)\对于范围内的 i(len(labels)-1)]返回标签

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

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

最后导入您的编辑文件,例如将 windrose_edit 导入为 wind2

并与

一起使用

winddir_ = 你的数据风速_ =您的数据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()

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

Below I have plotted a wind rose using Windrose based on this. Firstly, the legend is covering part of the rose but when I try to use loc to set it's location the legend disappears.

Secondly, the legend closing brackets are wrong i.e. [0.0 : 1.0[ any idea how I fix this to [0.0 : 1.0]

code:

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

解决方案

Copy the original windrose.py from your python folder to your desired working directory. Name the copy somehow else, e.g. windrose_edit.py. Edit the file and look for the get_labels() function. I edited like this, but you can adopt it to your purpose.

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

also you can increase the fontsize of the legend some lines below.

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

Finally import your edited file for example import windrose_edit as wind2

and use it with

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()

it's not beautiful although a relatively fast and lazy workaround

这篇关于Python Windrose图例括号格式和位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆