matplotlib画图——柱状图、折线图

import numpy as np
from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif'] = ['Times New Roman']  # 用来正常显示中文标签,如果想要用新罗马字体,改成 Times New Roman
C=['Client A','Client B','Client C','Client D','Global Test Avg']
Y=[0,20,40,60,80,100]
b_13=  [60.52,64.59,66.87,46.88,59.72]
b_14 = [61.98,66.51,63.82,43.35,58.92]
b_16 = [63.11,63.96,63.15,43.81,58.50]
b_17=  [61.85,64.84,68.23,48.26,60.80]
b_18 = [63.35,66.48,67.27,48.14,61.31]
b_19  = [67.19,57.35,54.51,43.26,58.10]


def auto_text(rects):
    for rect in rects:
        plt.text(rect.get_x(), rect.get_height(), rect.get_height(), ha='left', va='bottom',fontsize=30)


# 设置图形大小
width = 0.15
plt.figure(figsize=(40,16),dpi=80)
x = np.arange(len(C))  # x轴刻度标签位置
y = np.arange(len(Y))  # x轴刻度标签位置
rect0=plt.bar(x-3*width,b_13,width,label="baseline",alpha = 0.5,color = 'blue')
rect1=plt.bar(x-2*width,b_14,width,label="τ=1",alpha = 0.5,color = 'lightskyblue')
rect3=plt.bar(x-1*width,b_16,width,label="τ=5",alpha = 0.5,color = 'darkseagreen')
rect4=plt.bar(x,b_17,width,label="τ=10",alpha = 0.5,color = 'y')
rect5=plt.bar(x+1*width,b_18,width,label="τ=15",alpha = 0.5,color = 'indianred')
rect6=plt.bar(x+2*width,b_19,width,label="τ=20",alpha = 0.5,color='pink')

# 设置x轴的刻度
plt.xticks(x-width/2,C)
# 设置Y轴的刻度范围

plt.yticks([0, 20, 40, 60, 80, 100]) 
plt.ylabel('Dice(%)',fontsize=50)
auto_text(rect0)
auto_text(rect1)
auto_text(rect3)
auto_text(rect4)
auto_text(rect5)
auto_text(rect6)
plt.tick_params(labelsize=50) #刻度字体大小30
# 设置图例
plt.legend(fontsize=23)


# 展示
plt.show()

 

def plot_dataset1_loss():
    method1 = [0, 20.0, 55.93, 51.89, 64.05, 59.30, 62.19, 62.94, 66.44, 65.16, 65.96, 65.86, 60.97, 64.66, 67.14, 67.63,
              66.3, 63.82, 66.03, 62.77, 65.42, 69.35, 66.72, 65.12, 65.12, 66.06, 66.2, 67.04, 67.11, 67.01, 66.75,
              67.81, 69.12, 67.99, 68.02, 68.5, 68.8, 68.86, 66.97, 68.52, 68.23, 68.12, 68.38, 67.28, 67.94, 68.8,
              68.95, 68.69, 68.44, 68.35, 68.54, 69.15, 70.47, 69.67, 71.04, 70.27, 70.28, 69.74, 69.56, 69.39, 69.25,
              70.13, 70.47, 70.41, 70.49, 70.89, 69.5, 69.23, 69.08, 70.71, 70.56, 70.39, 70.13, 70.64, 69.87, 70.00,
              69.5, 72.00, 70.08, 70.52, 70.38, 70.38, 69.3, 68.60, 69.8, 70.49, 68.96, 70.61, 69.94, 69.71, 71.3,
              70.19, 69.65, 69.71, 70.30, 70.37, 69.58, 70.8, 69.65, 70.17]
    
    method2 = [2.0, 2.0, 4.64, 58.44, 63.78, 62.02, 66.09, 61.89, 66.21, 66.41, 69.03, 64.92, 65.60, 65.75, 69.17,
               67.83, 70.17, 71.89, 65.24, 71.24, 66.34, 68.03, 69.61, 69.26, 67.01, 66.77, 67.56, 68.34, 67.75, 66.75,
               67.01, 67.62, 66.83, 67.25, 67.25, 67.24, 67.56, 67.15, 67.86, 67.77, 66.47, 67.77, 67.83, 68.8, 68.02,
               67.58, 66.03, 67.58, 67.52, 68.73, 68.60, 68.86, 69.38, 68.8, 69.06, 68.86, 69.45, 68.93, 69.19, 69.65,
               69.25, 69.52, 68.93, 69.99, 69.78, 69.71, 70.39, 70.28, 68.92, 69.32, 69.58, 70.05, 69.85, 70.12, 69.65,
               69.65, 69.92, 70.12, 70.05, 69.17, 69.78, 70.19, 70.19, 70.8, 69.58, 68.93, 69.52, 69.78, 70.25, 69.72,
               69.32, 70.06, 69.78, 69.58, 69.24, 69.65, 69.16, 69.56, 69.52, 69.27]


    method3 = [0.399, 5.895, 42.76, 57.85, 55.1, 54.53, 56.36, 64.95, 68.49, 66.51, 66.22, 70.17, 66.06, 65.94, 64.63,
             70.17, 69.3, 67.04, 64.66, 65.53, 70.12, 70.28, 68.49, 66.05, 65.36, 67.38, 68.08, 69.24, 68.78, 69.03,
             68.19, 69.5, 69.95, 69.1, 69.24, 69.67, 69.24, 69.74, 68.17, 70.11, 69.59, 69.1, 70.6, 68.58, 69.66, 69.64,
             70.53, 71.6, 69.59, 69.85, 70.17, 70.26, 72.09, 71.64, 73.25, 71.94, 72.02, 71.3, 70.81, 71.46, 70.78,
             71.16, 72.99, 72.92, 72.09, 72.31, 71.32, 71.27, 70.84, 73.37, 71.8, 72.34, 72.19, 72.63, 71.69, 71.23,
             71.17, 74.44, 71.37, 71.58, 72.02, 72.02, 70.64, 70.54, 70.78, 72.56, 70.55, 72.09, 71.71, 71.05, 72.45,
             72.22, 71.41, 71.41, 71.71, 72.14, 70.98, 72.19, 71.11, 72.31]

    method4 = [6.5, 11.79, 52.68, 53.62, 58.13, 62.49, 64.94, 65.14, 63.46, 63.85, 65.59, 64.56, 64.21, 65.09, 65.02, 64.5,
            64.71, 65.8, 66.64, 66.35, 66.05, 66.35, 66.06, 65.69, 66.14, 67.15, 68.08, 68.89, 69.03, 69.22, 69.28,
            69.36, 69.5, 69.5, 69.57, 69.34, 69.28, 69.01, 69.02, 69.22, 69.02, 68.99, 68.71, 67.97, 67.7, 67.04, 67.3,
            66.72, 66.63, 66.38, 66.97, 67.51, 67.99, 68.08, 68.16, 68.16, 68.16, 68.16, 68.16, 68.16, 68.16, 68.26,
            68.43, 68.49, 68.49, 68.43, 68.53, 68.49, 68.43, 68.53, 68.53, 68.58, 68.58, 68.58, 67.86, 67.86, 67.9,
            67.9, 67.9, 67.96, 68.01, 68.01, 68.01, 68.01, 68.01, 68.01, 68.01, 68.01, 68.01, 68.01, 68.01, 68.01,
            68.06, 68.11, 68.11, 68.11, 68.11, 68.17, 68.17, 68.11]
    method5 = [2.80, 11.12, 36.41, 48.94, 64.4, 64.17, 63.88, 61.71, 64.03, 63.53, 66.92, 65.4, 66.3, 62.844, 68.06,
               63.235, 65.39, 61.57, 67.25, 65.73, 66.27, 63.01, 67.85, 63.92, 63.94, 65.66, 65.99, 66.77, 66.17, 66.95,
               67.04, 67.32, 67.95, 68.17, 67.02, 67.71, 68.06, 67.36, 66.7, 66.17, 67.16, 66.7, 68.06, 67.03, 67.24,
               66.11, 67.30, 67.03, 66.31, 67.83, 68.58, 68.17, 69.96, 68.72, 69.43, 69.37, 69.22, 68.93, 69.46, 69.28,
               69.56, 69.13, 69.1, 69.78, 68.83, 68.99, 69.64, 69.72, 69.36, 69.86, 69.56, 70.1, 69.05, 68.91, 69.78,
               69.1, 68.63, 69.39, 69.34, 69.34, 69.99, 69.17, 69.36, 69.03, 69.67, 69.25, 69.46, 69.74, 69.48, 69.55,
               69.84, 69.34, 70.36, 69.64, 69.39, 69.84, 69.67, 69.36, 69.02, 69.22]

    proposed = [2.0, 24.528, 37.83, 61.71, 64.47, 64.19, 66.66, 66.5, 66.64, 67.73, 67.58, 67.67, 67.7, 68.03, 68.71,
                 69.54, 69.58, 69.92, 69.88, 69.99, 69.27, 69.04, 70.39, 69.85, 70.95, 69.63, 70.3, 70.30, 69.73, 69.78,
                 69.74, 70.92, 70.84, 70.47, 70.6, 71.21, 71.26, 71.44, 71.36, 71.0, 71.75, 72.41, 72.78, 72.56, 72.47,
                 72.77, 72.03, 72.15, 72.44, 72.76, 72.03, 72.45, 73.76, 73.6, 74.35, 73.69, 74.18, 73.57, 73.78, 74.58,
                 73.22, 74.5, 74.09, 75.18, 74.63, 74.92, 72.69, 74.63, 73.61, 75.03, 74.14, 73.87, 73.50, 74.62, 74.56,
                 74.53, 73.8, 74.75, 73.64, 74.16, 74.49, 73.96, 73.87, 73.36, 74.29, 74.42, 73.22, 74.86, 74.39, 74.0,
                 75.12, 74.03, 74.26, 74.6, 74.53, 74.97, 74.08, 75.03, 74.8, 74.65]

    loss_dice=[method1,method2,method3,method4,method5,proposed]

    return loss_dice

 

 

def matplot_dataset(loss_dice):
    x1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
          21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
          41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
          61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
          81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]

    plt.plot(x1, loss_dice[0], color='g',linestyle='--')
    plt.plot(x1,loss_dice[1],color='r',linestyle='--')
    plt.plot(x1, loss_dice[2], color='y',linestyle='--')
    plt.plot(x1, loss_dice[3], color='b', linestyle='--')
    plt.plot(x1, loss_dice[4], color='c', linestyle='--')
    plt.plot(x1, loss_dice[5], color='m', linestyle='--')
    plt.title('This is the title',fontsize=16)  # 1.添加标题
    # plt.text(-2.5,30,'function y=x*x')#1.添加文字 第一、二个参数设置坐标
    # plt.annotate('这是一个示例注释',xy=(0,1),xytext=(-2,22),arrowprops={'headwidth':10,'facecolor':'r'})
    plt.xlabel('communication rounds',fontsize=18)
    plt.ylabel('Dice(%)',fontsize=18)
 
    #plt.plot(x, x * x, color='r')
    #plt.plot(x, x * 3, color='0.5')
    #plt.plot(x, x * 4, color=(0.1, 0.2, 0.3))
    plt.legend(['method1', 'method2','method3', 'method4','method5','proposed'])
    # 调整x轴和y轴的格式
    #plt.locator_params('x', nbins=20)
    plt.xlim(xmin=0, xmax=100)
    plt.ylim(ymin=50, ymax=90) //这里可以改刻度
    plt.tick_params(labelsize=18) #刻度字体大小30
# 设置图例

    plt.show()

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值