微信扫一扫打赏支持

matplotlib指定线条的颜色以及标记

matplotlib指定线条的颜色以及标记

一、总结

一句话总结:

color颜色
marker标记,markersize为标记大小
linestyle线样式,linewidth线宽
plt.plot(x,y,color='red', marker='o', linestyle='dashed',linewidth=2, markersize=12)

 

 

二、matplotlib指定线条的颜色以及标记

 

import numpy as np
import matplotlib.pyplot as plt
# 设置matplotlib库字体的非衬线字体为黑体
plt.rcParams["font.sans-serif"]=["SimHei"]
# 设置matplotlib库字体族为非衬线字体
plt.rcParams["font.family"]="sans-serif"

fig, ax = plt.subplots()
# 取消边框
for key, spine in ax.spines.items():
    # 'left', 'right', 'bottom', 'top'
    if key == 'left' or key == 'right':
        spine.set_visible(False)
plt.xticks([])
plt.yticks([])
x=[1,2,3,4,5]
y=[4,9,6,8,3]
y_mean=np.mean(y).repeat(5)
print(y_mean)
#plt.plot(x,y,'ro')
plt.plot(x,y,color='red', marker='o', linestyle='dashed',linewidth=2, markersize=12)
plt.plot(x,y_mean,'k--')
plt.text(0.2,6,r'x均值', fontdict={'size':16,'color':'r'})
plt.text(0.6,6,r'$:\mu_x$', fontdict={'size':16,'color':'r'})
plt.show()

 

 

 

 

 
posted @ 2020-11-10 14:59  范仁义  阅读(201)  评论(0编辑  收藏  举报