WindRoseAxe 生成不完整的轴

问题描述 投票:0回答:1

我刚刚遇到这个问题,以前从未发生过。

轴不完整。该代码在之前的运行中运行良好。

我不确定应该提供哪些细节来解决问题。请告诉我。

Python 版本:3.8.8(默认,2021 年 4 月 13 日,15:08:03)[MSC v.1916 64 位 (AMD64)]

matplotlib 版本 3.7.5

可以下载 *csv 格式的测试数据:https://drive.google.com/file/d/1nIIT0vTVOtj2B89Fxh1tzBLqsYQq_hXP/view?usp=drive_link

enter image description here

我的代码是:

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


file_path = 'the directory with csv file' 
# the code will process all the *csv files in the directory

has_legend = False
files = os.listdir(file_path)

def create_rose(file_name):
    # Create wind speed and direction variables
    # CSV data structure : Date , Time , Speed , Direction
    csv = np.genfromtxt(file_path + file_name, 
                    delimiter =',', skip_header =1)
    pdf_1 = file_path + 'with_legend_'+ file_name + '.pdf'
    pdf_2 = file_path + 'no_legend_'+ file_name + '.pdf'
    
    
    # ws: wind speed
    # wd: wind direction
    # in python, range index starts with zero
    # ws = csv[ : , 2]
    
    ws = csv[ : , 0]
    wd = csv[ : , 1] + 15
    speed_bin = np.arange(0, 4, 0.5)
    
    
    len(ws)
    
    ax = WindroseAxes.from_ax()
    ax.bar(wd, ws, normed =True, opening=1, edgecolor='white', bins = speed_bin, cmap = cm.jet, nsector = 12) 
    ax.set_xticklabels([90, 45, 0, 315, 270, 225, 180, 135])
          
    if(has_legend):
        ax.set_legend()
        ax.legend(loc ='lower right', decimal_places=2)
        plt.savefig(pdf_1)
    else:
        plt.savefig(pdf_2)
            
for file_x in files:
    print(file_x)
    create_rose(file_x)

print('All is finished')
python python-3.x windrose
1个回答
0
投票

通过将 conda 从版本 4 更新到版本 24 来解决。 作为一个 python 包用户,我不知道。感谢任何能解释的人。 谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.