《Python数据可视化之matplotlib实践》 源码 第三篇 演练 第九章
2023-09-11 14:19:19 时间
图 9.1
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import matplotlib.pyplot as plt import numpy as np fig=plt.figure() ax=fig.add_subplot(111) font={"family":"monospace", "color":"maroon", "weight":"bold", "size":6} x=np.linspace(0.0, 2*np.pi, 500) y=np.cos(x)*np.sin(x) ax.plot(x, y, color="k", ls="-", lw=2) ax.set_title("keyword mode is 'fontdict=font'", fontdict=font) ax.text(1.5, 0.4, "cos(x)*sin(x)", fontdict=font) ax.set_xlabel("time (h)", **font) ax.set_ylabel(r"$\Delta$height (cm)", **font) ax.set_xlim(0, 2*np.pi) plt.show()
=============================================
图 9.2
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import matplotlib.pyplot as plt import numpy as np fig=plt.figure() ax=fig.add_subplot(111) font={"family":"serif", "color":"navy", "weight":"black", "size":16} x=np.linspace(0.0, 2*np.pi, 500) y=np.cos(2*x)*np.sin(2*x) ax.plot(x, y, color="k", ls="-", lw=2) ax.set_title("keyword mode is '**font'", **font) ax.text(1.5, 0.52, "cos(2*x)*sin(2*x)", **font) ax.set_xlabel("time (h)", **font) ax.set_ylabel(r"$\Delta$height (cm)", **font) ax.set_xlim(0, 2*np.pi) plt.show()
=============================================
图 9.3
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import matplotlib.pyplot as plt import numpy as np font=dict(family="serif", color="navy", weight="black", size=16) color="skyblue" linewidth=3 fig=plt.figure() ax=fig.add_subplot(111) linestyleList=["-", "--", "-.", ":"] x=np.arange(1, 11, 1) y=np.linspace(1, 1, 10) ax.text(4, 4.0, "line styles", **font) for i, ls in enumerate(linestyleList): ax.text(0, i+0.5, "'{}'".format(ls), **font) ax.plot(x, (i+0.5)*y, linestyle=ls, color=color, linewidth=linewidth) ax.set_xlim(-1, 11) ax.set_ylim(0, 4.5) ax.margins(0.2) ax.set_xticks([]) ax.set_yticks([]) plt.show()
=============================================
图 9.4
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import matplotlib.pyplot as plt import numpy as np font_style=dict(family="serif", color="navy", weight="black", size=12) line_marker_style=dict(linestyle=":", linewidth=2, color="maroon", markersize=10) fig=plt.figure() ax=fig.add_subplot(111) msNameList=["'.'--point marker", "','--piexel marker", "'o'--circle marker", "'v'--triangle_down_marker", "'^'--triangle_up marker", "'<'--triangle_left marker", "'>'--triangle_right marker", "'1'--tri_down marker", "'2'--tri_up marker", "'3'--tri_left marker", "'4'--tri_right marker", "'s'--square marker", "'p'--pentagon marker", "'*'--star marker", "'h'--hexagon1 marker", "'H'--hexagon2 marker", "'+'--plus marker", "'x'--x marker", "'D'--diamond marker", "'d'--thin_diamond marker", "'|'--vline markder", "'_'--hline marker"] markerstyleList=['.', ',', 'o', 'v', '^', '<', '>', '1', '2', '3', '4', 's', 'p', '*', 'h', 'H', '+', 'x', 'D', 'd', '|', '_'] x=np.arange(5, 11, 1) y=np.linspace(1, 1, 6) ax.text(4, 23, "marker styles", **font_style) for i, ms in enumerate(markerstyleList): ax.text(0, i+0.5, msNameList[i], **font_style) ax.plot(x, (i+0.5)*y, marker=ms, **line_marker_style) ax.set_xlim(-1, 11) ax.set_ylim(0, 24) ax.margins(0.3) ax.set_xticks([]) ax.set_yticks([]) plt.show()
=============================================
图 9.5
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np mpl.rcParams["font.sans-serif"]=["SimHei"] mpl.rcParams["axes.unicode_minus"]=False x=np.arange(1, 13, 1) y=np.array([12, 34, 22, 30, 18, 13, 15, 19, 24, 28, 23, 27]) fig, ax = plt.subplots(2, 2) ax[0, 0].scatter(x, y*1.5, marker=r"$\clubsuit$", c="#fb8072", s=500) ax[0, 0].locator_params(axis="x", tight=True, nbins=11) ax[0, 0].set_xlim(0, 13) ax[0, 0].set_xticks(x) ax[0, 0].set_title('显示样式 “%s” 的散点图' % r"$\clubsuit$") ax[0, 1].scatter(x, y-2, marker=r"$\heartsuit$", s=500) ax[0, 1].locator_params(axis="x", tight=True, nbins=11) ax[0, 1].set_xlim(0, 13) ax[0, 1].set_xticks(x) ax[0, 1].set_title('显示样式 “%s” 的散点图' % r"$\heartsuit$") ax[1, 0].scatter(x, y+7, marker=r"$\diamondsuit$", c="#fb8072", s=500) ax[1, 0].locator_params(axis="x", tight=True, nbins=11) ax[1, 0].set_xlim(0, 13) ax[1, 0].set_xticks(x) ax[1, 0].set_title('显示样式 “%s” 的散点图' % r"$\diamondsuit$") ax[1, 1].scatter(x, y-9, marker=r"$\spadesuit$", c="#8dd3c7", s=500) ax[1, 1].locator_params(axis="x", tight=True, nbins=11) ax[1, 1].set_xlim(0, 13) ax[1, 1].set_xticks(x) ax[1, 1].set_title('显示样式 “%s” 的散点图' % r"$\spadesuit$") plt.suptitle("不同原始字符串作为标记类型的展示效果", fontsize=16, weight="black") plt.show()
=============================================
图 9.6
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import matplotlib.pyplot as plt import numpy as np font_style=dict(family="serif", weight="black", size=12) line_marker_style1=dict(linestyle="--", linewidth=2, color="maroon", markersize=10) line_marker_style2=dict(linestyle="--", linewidth=2, color="cornflowerblue", markersize=10) line_marker_style3=dict(linestyle="--", linewidth=2, color="turquoise", markersize=10) fig=plt.figure() ax=fig.add_subplot(111, facecolor="honeydew") x=np.linspace(0, 2*np.pi, 500) y=np.sin(x)*np.cos(x) ax.plot(x, y, dashes=[10, 2], label="dashes=[10, 2]", **line_marker_style1) ax.plot(x, y+0.2, dashes=[3, 1], label="dashes=[3, 1]", **line_marker_style2) ax.plot(x, y+0.4, dashes=[2, 2, 8, 2], label="dashes=[2, 2, 8, 2]", **line_marker_style3) ax.axis([0, 2*np.pi, -0.7, 1.2]) ax.legend(ncol=3, bbox_to_anchor=(0.00, 0.95, 1.0, 0.05), mode="expand", fancybox=True, shadow=True, prop=font_style) plt.show()
=============================================
图 9.7
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import matplotlib.pyplot as plt import numpy as np font_style=dict(family="sans-serif", color="saddlebrown", weight="semibold", size=16) line_marker_style=dict(linestyle=":", linewidth=2, color="cornflowerblue", markerfacecoloralt="lightgrey", marker="o", markersize=10) fig=plt.figure() ax=fig.add_subplot(111) fillstyleList=["full", "left", "right", "bottom", "top", "none"] x=np.arange(3, 11, 1) y=np.linspace(1, 1, 8) ax.text(4, 6.5, "fill styles", **font_style) for i, fs in enumerate(fillstyleList): ax.text(0, i+0.4, "'{}'".format(fs), **font_style) ax.plot(x, (i+0.5)*y, fillstyle=fs, **line_marker_style) ax.set_xlim(-1, 11) ax.set_ylim(0, 7) ax.margins(0, 3) ax.set_xticks([]) ax.set_yticks([]) plt.show()
=============================================
相关文章
- 单柱柱形图与多柱柱形图的绘制 基于python-matplotlib库
- 【无标题】python——详解collections工具库
- Python __init__.py
- 人生苦短,我用Python!为什么现在越来越多的人转行python?
- 【python实战】拒绝黄牛!我要用python原价冲周董演唱会~Python自动秒杀抢票脚本
- Python和R代码机器学习算法速查对比表
- 源码编译vi过程中进行配置时报“checking if compile and link flags for Python are sane... no: PYTHON DISABLED”怎么办?
- python 文件打开关闭及读写,文件的定位tell()和seek(),文件备份
- python之模块chunk,了解即可
- 《Python和HDF 5大数据应用》——导读
- 《像计算机科学家一样思考Python》——第4章 案例研究:接口设计 4.1 乌龟世界
- 《Python数据可视化编程实战》——5.4 在matplotlib中创建动画
- python Python程序的架构
- Python 可视化教程大全之 使用 Matplotlib 和 Seaborn 进行数据可视化
- Python 教程之如何使用 matplotlib 在 python 中绘制数学函数
- Python中关于进度条的6个实用技巧
- python绘图库matplotlib:刻度线的方向调整, in, out, inout
- 《Python数据可视化之matplotlib实践》 源码 第二篇 精进 第六章
- 《Python数据可视化之matplotlib实践》 源码 第一篇 入门 第三章
- 《Python数据可视化之matplotlib实践》 源码 第一篇 入门 第二章
- Python基础之文件操作+复制文件目录+统计目录大小
- Python 工具 之 Windows 上 python 虚拟环境的搭建与简单使用的相关说明
- 【python百度智能云】:Python — 三种获取__VIEWSTATE、__VIEWSTATEGENERATOR、__EVENTVALIDATION方法。