赵走x博客
网站访问量:151913
首页
书籍
软件
工具
古诗词
搜索
登录
34、延伸阅读:箱体;箱须、 离群值的含义和计算方法
33、箱线图
32、饼图
30、堆积析线图、 间断条形图和阶梯图
29、参数探索:设置柱体的填充样式
28、绘制统计图形:分块图
27、绘制统计图形:堆积图
26、绘制统计图形:条形图
25、绘制统计图形:柱状图
24、函数errorbar():用于绘制误差棒图
23、函数boxplot():用于绘制箱线图
22、函数stem():用于绘制棉棒图
21、函数 scatter():用于绘制气泡图
20、函数polar():用于绘制极线图
19、函数pie():用于绘制饼图
18、函数hist():用于绘制直方图
17、函数barh():用于绘制条形图
16、函数bar():用于绘制柱状图
15、使用统计函数绘制简单图形
14、函数组合应用
13、函数legend()一一标示不同图形的文本标签图例
12、函数title():添加图形内容的标题
11、函数text()一一添加图形内容细节的无指向型注释文本
10、函数annotate()一一添加图形内容细节的指向型注释文本
9、 函数axvspan()一一绘制垂直于 x 轴的参考区域
8、函数axhline()一一绘制平行于 x 轴的水平参考线
7、函数 grid():绘制刻度线
6、函数xlabel():设置 x 轴的标签文本
5、函数xlim():设置 x 轴的数值显示范围
4、函数scatter():寻找变量之间的关系
3、函数plot():展现变量的趋势变化
2、使用函数绘制matplotlib的图表组成元素
1、图表欣赏
14、函数组合应用
资源编号:76002
人工智能
Python数据可视化之matplotlib实践
热度:100
上节将绘制图1.1的重要组成元素的函数从函数功能、 调用签名、 参数说明和调用展示等方面讲解使用方法, 进一步, 在调用展示中又通过代码实现和运行结果两方面详细解释了绘制这些组成元素的函数的使用方法
上节将绘制图1.1的重要组成元素的函数从函数功能、 调用签名、 参数说明和调用展示等方面讲解使用方法, 进一步, 在调用展示中又通过代码实现和运行结果两方面详细解释了绘制这些组成元素的函数的使用方法。因此,通过这些函数的多维度学习,读者基本可以将图1.1中的内容很好地复现出来, 接下来, 就让我们看看绘制图1.1的源代码, 如下所示。 ``` 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.rand(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') # some clean up(removing chartjunk) # turn the top spine and the right spine off for spine in plt.gca().spines.keys(): print(spine) if spine == 'top' or spine == 'right': plt.gca().spines[spine].set_color('none') # turn bottom tick for x-axis on plt.gca().xaxis.set_ticks_position('bottom') # set tick_line position of bottom # leave left ticks for y-axis on plt.gca().yaxis.set_ticks_position('left') # set tick_line position of left # set x,yaxis limit plt.xlim(0.0, 4.0) plt.ylim(-3.0, 3.0) # set axes labels plt.ylabel('y_axis') plt.xlabel('x_axis') # set x,yaxis grid plt.grid(True, ls=':', color='r') # add a horizontal line across the axis plt.axhline(y=0.0, c='r', ls='--', lw=2) # add a vertical span across the axis plt.axvspan(xmin=1.0, xmax=2.0, facecolor='y', alpha=.3) # set annotating info plt.annotate('maximum', xy=(np.pi / 2, 1.0), xytext=((np.pi / 2) + 0.15, 1.5), weight='bold', color='r', arrowprops=dict(arrowstyle='->', connectionstyle='arc3', color='r')) plt.annotate('spines', xy=(0.75, -3), xytext=(0.35, -2.25), weight='bold', color='b', arrowprops=dict(arrowstyle='->', connectionstyle='arc3', color='b')) plt.annotate('', xy=(0, -2.78), xytext=(0.4, -2.32), arrowprops=dict(arrowstyle='->', connectionstyle='arc3', color='b')) plt.annotate('', xy=(3.5, -2.98), xytext=(3.6, -2.70), arrowprops=dict(arrowstyle='->', connectionstyle='arc3', color='b')) # set text info plt.text(3.6, -2.70, "'|' is tickline", weight='bold', color='b') plt.text(3.6, -2.95, "3.5 is ticklabel", weight='bold', color='b') # set title plt.title("structure of matplotlib") # set legend() plt.legend() plt.show() ``` 在上面的源代码中, 除了用线框圈起来的部分我没有阐述, 其余部分都已经介绍过了, 线框部分会在接下来的章节中详细给大家讲解。 现在, 读者就动手输入上面的代码, 看看输出结果是什么样的?能否感受到matplotlib绘图的精细与精美? 