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

先上效果图:
图一

基本操作,指定坐标轴范围

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

图二

子图模式

plt.subplot(nrows, ncols, plot_number)

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

格式控制

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

format_string颜色字符

format_string风格字符

format_string标记字符

关于**kwargs

可选参数列表

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容