python数据分析与展示(matplotlib库基础)

先上效果图:
图一

python数据分析与展示(matplotlib库基础)_第1张图片
基本操作,指定坐标轴范围

import matplotlib.pyplot as plt
import numpy as np

x_value=np.linspace(1,10)
y_value=np.sin(x_value)
plt.axis([1,10,-1,1])
plt.xlabel("x")
plt.ylabel("sin(x)")
plt.plot(x_value,y_value)
#plt.savefig("G:\Pictures\Figure_1.png")
plt.show()

图二

python数据分析与展示(matplotlib库基础)_第2张图片
子图模式

plt.subplot(nrows, ncols, plot_number)

在全局绘图区域中创建一个nrows*ncols的分区体系,并定位到第plot_number个子绘图区域,区域计数从1开始。
图三

python数据分析与展示(matplotlib库基础)_第3张图片
格式控制

import matplotlib.pyplot as plt
import numpy as np

x_value=np.linspace(1,10)
y_value=np.sin(x_value)

plt.plot(x_value,y_value,"b-")
plt.plot(x_value,y_value,"r *")

plt.show()

plt.plot(x, y, format_string, **kwargs)

参数 含义
x X轴数据,列表或数组,可选
y Y轴数据,列表或数组
format_string 控制曲线的格式字符串,可选
**kwargs 第二组或更多(x,y,format_string)

当绘制多条曲线时,各条曲线的x不能省略

关于format_string

python数据分析与展示(matplotlib库基础)_第4张图片
format_string颜色字符

python数据分析与展示(matplotlib库基础)_第5张图片
format_string风格字符

python数据分析与展示(matplotlib库基础)_第6张图片
format_string标记字符

关于**kwargs

python数据分析与展示(matplotlib库基础)_第7张图片
可选参数列表

一切的一切,尽在print(plt.plot.__doc__)

你可能感兴趣的:(python数据分析与展示(matplotlib库基础))