python柱形图填充

将画出的柱形图填充各种形状

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")

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/sunjiaxing_1/article/details/106607125