基于python matplotlib的应用

本文详细介绍了使用Python的Matplotlib库进行数据可视化的方法,通过具体的代码示例展示了如何绘制不同类型的图表,包括设置颜色、透明度等属性,适用于初学者和需要深入掌握Matplotlib绘图技巧的开发者。
摘要由CSDN通过智能技术生成
import  matplotlib.pyplot  as plt
import random
import numpy as np
import pandas as pd
def MaxMinNormalization(x,Max,Min):
    x = (x - Min) / (Max - Min);
    return x/3.00124732715609
def graphpic(w,h,p,q,list66,listgg):
    sx = 0
    num = 2
    sy = 0.2 + 4* (h + q)
    sum = 0
    for i,kkk in zip(list66,listgg):
        if i==0:
            rect3 = plt.Rectangle((sx, sy), w+p, h+q, color='tomato',alpha=0.6)
            ax.add_patch(rect3)
        elif i==3:
            rect3=plt.Rectangle((sx, sy), (w+p), h+q, color='lime',alpha=0.6)
            ax.add_patch(rect3)
        else:
            rect3 = plt.Rectangle((sx, sy), (w+p), h + q, color='tan',alpha=0.6)
            ax.add_patch(rect3)
        sum+=kkk
        sx+=(w+p)
        #q=2*q
def graphpic2(w,h,p,q,list66,listgg):
    sx = 0
    num = 2
    sy = 0.2 + 3 * (h + q)
    sum = 0
    for i,kkk in zip(list66,listgg):
        if i==0:
            rect3 = plt.Rectangle((sx, sy), w+p, h+q, color='tomato',alpha=0.6)
            ax.add_patch(rect3)
        elif i==3:
            rect3=plt.Rectangle((sx, sy), (w+p), h+q, color='tan',alpha=0.6)
            ax.add_patch(rect3)
        else:
            rect3 = plt.Rectangle((sx, sy), (w+p), h + q, color='lime',alpha=0.6)
            ax.add_patch(rect3)
        sum+=kkk
        sx+=(w+p)
        #p=2*p
        #q=2*q
def graphpic3(w,h,p,q,list66,listgg):
    sx=0
    num=2
    sy=0.2+2*(h+q)
    sum=0
    for i,kkk in zip(list66,listgg):
        if i==0:
            rect3 = plt.Rectangle((sx, sy), w+p, h+q, color='tomato',alpha=0.6)
            ax.add_patch(rect3)
        elif i==3:
            rect3=plt.Rectangle((sx, sy), (w+p), h+q, color='tan',alpha=0.6)
            ax.add_patch(rect3)
        else:
            rect3 = plt.Rectangle((sx, sy), (w+p), h + q, color='lime',alpha=0.6)
            ax.add_patch(rect3)
        sum+=kkk
        sx+=(w+p)
        #p=2*p
        #q=2*q
def graphpic4(w,h,p,q,list66,listgg):
    sx=0
    num=3
    sy=0.2+h+q
    sum = 0
    for i,kkk in zip(list66,listgg):
        if i==0:
            rect3 = plt.Rectangle((sx, sy), w+p, h+q, color='tomato',alpha=0.6)
            ax.add_patch(rect3)
        elif i==3:
            rect3=plt.Rectangle((sx, sy), (w+p), h+q, color='tan',alpha=0.6)
            ax.add_patch(rect3)
        else:
            rect3 = plt.Rectangle((sx, sy), (w+p), h + q, color='lime',alpha=0.6)
            ax.add_patch(rect3)
        sum+=kkk
        sx+=(w+p)
        #p=2*p
        #q=2*q
def graphpic5(w,h,p,q,list66,listgg):
    sx=0
    num=4
    sy=0.2
    sum=0
    for i,kkk in zip(list66,listgg):
        if i==0:
            rect3 = plt.Rectangle((sx, sy), w+p, h+q, color='tomato',alpha=0.6)
            ax.add_patch(rect3)
        elif i==3:
            rect3=plt.Rectangle((sx, sy), (w+p), h+q, color='tan',alpha=0.6)
            ax.add_patch(rect3)
        else:
            rect3 = plt.Rectangle((sx, sy), (w+p), h + q, color='lime',alpha=0.6)
            ax.add_patch(rect3)
        sum+=kkk
        sx+=(w+p)
        #p=2*p
        #q=2*q

def Randomlist(t,no):
    randomlist=[]
    for qq in range(no):
        randomlist.append(t)
    return randomlist
def getDu(zeze):
    listzeze=[]
    for boy in zeze:
        listzeze.append(boy)
    return listzeze
def pdread(getdd):
    nba=[]
    for getpp in  getdd:
        nba.append(getpp)
    return nba
if __name__ == '__main__':
    list = []
    wr = pd.read_excel("预处理数据.xlsx")
    ws = wr.num
    length = []
    for kk in ws:
        length.append(kk)
    for i in length:
        t = MaxMinNormalization(i, max(length), min(length))
        list.append(t)

    fig = plt.figure()
    ax = fig.add_subplot(111)   #创建子图

    # list=[0,2,3,0,2]
    # list2=[3,3,0,2,0]
    # list3=[2,3,0,0,2]
    # list4=[0,0,2,3,0]
    # list5=[3,3,2,2,3]
    # list=Randomlist(0,243)
    # list2=Randomlist(2,243)
    # list3=Randomlist(3,243)
    list1=pdread(wr.角度1)
    list2=pdread(wr.角度2)
    list3=pdread(wr.角度3)
    list4=pdread(wr.角度4)
    list5=pdread(wr.角度5)
    graphpic(0,0,0.004,0.1,list1,list)
    graphpic2(0,0,0.004,0.1,list2,list)
    graphpic3(0,0,0.004,0.1,list3,list)
    graphpic4(0, 0, 0.004, 0.1, list4,list)
    #list55=[2,2,3,0,3]
    #listss=[0.1, 0.2, 0.6, 0.05, 0.05]
    graphpic5(0, 0, 0.004, 0.1, list5,list)
    labletext=['novelty','motavition','experiment','relate work','writing']
    for label in range(5):
        plt.text(-0.08,0.25+0.1*label,labletext[label])
    # graphpic4(0,0,0.1,0.1,list4)
    # graphpic5(0,0,0.1,0.1,list5)
    # rect = plt.Rectangle((0.1,0.2),0.4,0.3, color="red")# (0.1,0.2)为左下角的坐标,0.4,0.3为宽和高,负数为反方向,红色填充
    # rect2=plt.Rectangle((0.1+0.4,0.2),0.4,0.3, color="green")
    #
    # ax.add_patch(rect)
    # ax.add_patch(rect2)
    plt.axis('off')
    plt.show()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值