图  9.1

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

 

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

 

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

 

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

 

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

 

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

 

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实践》 源码 第三篇 演练 第九章的更多相关文章

  1. Python数据可视化——使用Matplotlib创建散点图

    Python数据可视化——使用Matplotlib创建散点图 2017-12-27 作者:淡水化合物 Matplotlib简述: Matplotlib是一个用于创建出高质量图表的桌面绘图包(主要是2D ...

  2. python 数据可视化(matplotlib)

    matpotlib 官网 :https://matplotlib.org/index.html matplotlib 可视化示例:https://matplotlib.org/gallery/inde ...

  3. Python数据可视化库-Matplotlib(一)

    今天我们来学习一下python的数据可视化库,Matplotlib,是一个Python的2D绘图库 通过这个库,开发者可以仅需要几行代码,便可以生成绘图,直方图,功率图,条形图,错误图,散点图等等 废 ...

  4. Python数据可视化之Matplotlib实现各种图表

    数据分析就是将数据以各种图表的形式展现给领导,供领导做决策用,因此熟练掌握饼图.柱状图.线图等图表制作是一个数据分析师必备的技能.Python有两个比较出色的图表制作框架,分别是Matplotlib和 ...

  5. 机器学习-数据可视化神器matplotlib学习之路(三)

    之前学习了一些通用的画图方法和技巧,这次就学一下其它各种不同类型的图.好了先从散点图开始,上代码: from matplotlib import pyplot as plt import numpy ...

  6. Python数据可视化利器Matplotlib,绘图入门篇,Pyplot介绍

    Pyplot matplotlib.pyplot是一个命令型函数集合,它可以让我们像使用MATLAB一样使用matplotlib.pyplot中的每一个函数都会对画布图像作出相应的改变,如创建画布.在 ...

  7. Python数据可视化库-Matplotlib(二)

    我们接着上次的继续讲解,先讲一个概念,叫子图的概念. 我们先看一下这段代码 import matplotlib.pyplot as plt fig = plt.figure() ax1 = fig.a ...

  8. Python数据可视化之matplotlib

    常用模块导入 import numpy as np import matplotlib import matplotlib.mlab as mlab import matplotlib.pyplot ...

  9. python数据可视化(matplotlib)

  10. python数据可视化-matplotlib入门(7)-从网络加载数据及数据可视化的小总结

    除了从文件加载数据,另一个数据源是互联网,互联网每天产生各种不同的数据,可以用各种各样的方式从互联网加载数据. 一.了解 Web API Web 应用编程接口(API)自动请求网站的特定信息,再对这些 ...

随机推荐

  1. 腾讯视频遇到“前设备播放4K可能引发卡顿等异常,建议降低清晰度”

    腾讯视频遇到"前设备播放4K可能引发卡顿等异常,建议降低清晰度". 解决方法: 在菜单-设置-播放设置-勾选"开启硬件加速"-应用,然后退出腾讯视频,重新打开腾 ...

  2. 构建SaaS能力,加速数字化转型!猪齿鱼将在华为云快成长直播间开讲!

    时代的浪潮驱动着企业数字化转型.伴随着新基建.云计算成为国家战略的重要环节之一,"千行百业"开始专注于数字化转型,企业纷纷使用软件提升研发.销售.市场.消费者等不同场景下的效率,S ...

  3. idea编译报错 sun.misc.BASE64Decoder升级处理

    idea编译报错 sun.misc.BASE64Decoder升级处理 警告:17:01:15 /deploy/jenkins/workspace/auto-java-test/utils/Image ...

  4. 记录一次MySQL多表查询,order by不走索引的情况.

    首先是表结构,部分字段脱敏已删除 CREATE TABLE `log_device_heart` ( `id` int unsigned NOT NULL AUTO_INCREMENT, `devic ...

  5. C#.Net筑基-集合知识全解

    01.集合基础知识 .Net 中提供了一系列的管理对象集合的类型,数组.可变列表.字典等.从类型安全上集合分为两类,泛型集合 和 非泛型集合,传统的非泛型集合存储为Object,需要类型转.而泛型集合 ...

  6. FFmpeg如何将一个gif嵌入视频指定位置并指定显示时间

    背景 很简单的需求:我需要将一个gif嵌入到视频里面的指定位置,并要指定时间播放: 环境 windows11 64位专业版 ffmpeg version 2022-04-07-git-607ecc27 ...

  7. Stable Diffusion(一)Stable Diffusion 原理

    Stable Diffusion原理 此文为译文,原文见: https://stable-diffusion-art.com/how-stable-diffusion-work/ Stable Dif ...

  8. 使用AWS Glue进行 ETL 工作

    数据湖 数据湖的产生是为了存储各种各样原始数据的大型仓库.这些数据根据需求,进行存取.处理.分析等.对于存储部分来说,开源版本常见的就是 hdfs.而各大云厂商也提供了各自的存储服务,如 Amazon ...

  9. 前端 Array.sort() 源码学习

    源码地址 V8源码Array 710行开始为sort()相关 Array.sort()方法是那种排序呢? 去看源码主要是源于这个问题 // In-place QuickSort algorithm. ...

  10. 【SLAM】ORB_SLAM3 初步调试运行详细记录

    前言 相关解析及参考: 超详细解读ORB-SLAM3单目初始化(下篇) ORB_SLAM3和之前版本有什么不同?_小白学视觉的技术博客_51CTO博客 orbslam3 官方源码地址:https:// ...