matplotlib.pyplot知识梳理

it2023-12-16  78

散点图

scatter c-颜色 s-大小(点面积而非直径) marker-记号(https://matplotlib.org/)

height=[161,170,182,175,173,165] weight=[50,58,80,70,69,55] plt.scatter(height,weight)

折线图

plot 1.numpy导入函数, matplotlib.dates as mdates loadtxt(,delimiter,skiprows,usecols,unpack,converters = {0:mdates.strpdate2num()} 2.linspace

x = np.linspace(-20,20,100) y = x**2 plt.plot(x,y) #上证综指导入 import matplotlib.dates as mdates date,open1,close = np.loadtxt(r'C:\Users\ning7\Downloads\4_素材文件和源代码\000001.csv',delimiter = ',', skiprows = 1, usecols = (0,1,4), converters = {0:mdates.strpdate2num('%m/%d/%Y')},unpack=True)

条形图

bar barh

# 条形图 N=5 y=[20,10,30,25,15] index = np.arange(N) bar1 = plt.bar(x=index, height=y, width=0.3, bottom=10, color='red') plt.show() #并列 index = np.arange(4) sales_BJ=[52,55,63,53] sales_SH=[44,66,55,41] bar_width=0.3 plt.bar(index, sales_BJ, bar_width) plt.bar(index+bar_width, sales_SH, bar_width) plt.show() #叠放 index = np.arange(4) sales_BJ=[52,55,63,53] sales_SH=[44,66,55,41] bar_width=0.3 plt.bar(index, sales_BJ, bar_width) plt.bar(index, sales_SH, bar_width,bottom = sales_BJ) plt.show()

直方图

hist

饼状图

pie

箱形图

boxplot

子图

plt.figure fig.add_subplot(1,1,1)–面向对象

plt.subplot(221)

最新回复(0)