python中使用函数matplotlib的图表组成元素代码实战及详细讲解

本文通过实例代码介绍了Python中matplotlib库创建图表的基本元素,包括设置坐标轴范围、标签,绘制网格线、水平参考线、参考区域,添加注释文本、标题和图例,特别强调了中文标签的处理方法以及线条颜色和风格的选择。
摘要由CSDN通过智能技术生成
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm as cm

# define data 数据设置
x = np.linspace(0.5,3.5,100)
y = np.sin(x)
y1 = np.random.randn(100)

# scatter figure 散点图绘制
plt.scatter(x,y1,c='0.25',label='scatter figure')

# plot figure 连续线条的绘制
plt.plot(x,y,ls='--',lw=2,label='plot figure')

# set x,yaxis limit x,y轴的范围设置
plt.xlim(0,4)
plt.ylim(-3,3)

# set axes labels 设置x,y轴的名称,前面两行是为了中文显示而写的
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
plt.ylabel('y轴')
plt.xlabel('x轴')

# set x,yaxis grid 设置背景网格线
plt.grid(True,ls=':',color='r')

# add a horizontal line across the axis 参考线设置
plt.axhline(y=0,c='r',ls='--',lw=2)

# set a vertical span across the axis 参考区间设置
plt.axvspan(xmin=1.0,xmax=2.0,facecolor='y',alpha=0.3)
plt.axhs
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值