Python在氣象中的應(yīng)用

-5- 繪制小提琴圖

def Violin_chart(self, data_list, xticks_name_List, title, savepath, show=False):
        '''
        Function:This script is used to draw a violin plot.
        Athor:xiaohuoya
        Date:2020-05-28
        Eg: -1- data_list: the data list
            -2- xticks_name_List: the xticks name list
            -3- savepath: the figure save path
        '''
        import matplotlib.pyplot as plt
        import seaborn as sns

        fig, ax = plt.subplots(1, 1, constrained_layout=True, figsize=(8, 5))
        plt.style.use(self.pltstyle)
        sns.violinplot(cut=0, data=data_list, width=self.wd)
        plt.xticks(self.xticks_list[0:len(data_list)],
                   xticks_name_List, rotation=self.rot)
        ax.set_title(title, {'size': self.fs, 'color': self.cl}, loc='left')
        if show == True:
            plt.savefig(savepath, dpi=self.dpi)
            plt.show()
        elif show == False:
            plt.savefig(savepath, dpi=self.dpi)

1.此代碼有些許簡(jiǎn)陋,仍處于完善之中,不過(guò)可以提供一種繪圖思路
2.補(bǔ)充一下默認(rèn)設(shè)置:

class Draw:
    def __init__(self):
        self.pltstyle = 'ggplot'
        self.wd = 0.5 
        self.xticks_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
                            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
        self.rot = 45
if (__name__ == '__main__'):
    D.rot = 0
    D.Violin_chart( [pr_6,pr_6_obs,pr,pr_obs],['pr_6','pr_6_obs','pr_7','pr_7_obs'],'Made in xiaohuoya','./violin.pdf',show=False)
微信圖片_20220528112838.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容