import pandas as pd import numpy as np import matplotlib.pyplot as plt %matplotlib inline plt.rcParams["font.sans-serif"] = "Simhei" #填充符号 marks = ["o","X","+","*","O","."] #设置X,Y轴的值 y = np.random.randint(10,100,len(marks)) x = range(len(marks)) #画图 bars = plt.bar(x,y,color="w",edgecolor="k") #填充 for bar,mark in zip(bars,marks): bar.set_hatch(mark) #其他设置 plt.title("柱形图填充",fontsize = 20) plt.xlabel("柱形",fontsize = 20) plt.xticks(x,marks,fontsize = 20) plt.savefig("out/1.png",dpi=200,bbox_inches="tight")
用于写论文时,黑白印刷可分辨的代码。
import matplotlib.pyplot as plt import numpy as np #构建数据 x_data =['nodesTotalNumber', 'totalPathLength', 'pathNodesNumber','NodeUtilization','time'] Y1 = [163.1,17.38,14,26.99,17.66] Y2 = [56,23.5,13,23.21,7.106] Y3 =[11.2,15.69,7,62.5,2.499] bar_width = 0.3 marks = ['o','X','+','*','O'] y = np.random.randint(20,180,len(marks)) m =np.arange(len(x_data)) plt.bar(x=m, height=Y1, label='ManyobstaclesRRT', width=bar_width,hatch='**',color='w',edgecolor='k') plt.bar(x=m + bar_width, height=Y2, label='ManyobstaclesRRT*', width=bar_width,hatch='xxx',color='w',edgecolor='k') plt.bar(x=m +bar_width + bar_width, height=Y3, label='ManyobstaclesImprovedRRT',width=bar_width,hatch='',color='w',edgecolor='k') plt.xticks(range(0, 5), ['nodesTotalNumber', 'totalPathLength', 'pathNodesNumber', 'NodeUtilization', 'time']) plt.xticks(fontsize=13) #显示图例 plt.legend() plt.show() plt.savefig('1.png',dpi=200,bbox_inches='tight')