首页 > 其他分享 >Bk1_Ch10_01

Bk1_Ch10_01

时间:2024-07-17 14:20:57浏览次数:4  
标签:Ch10 01 color annotate set Bk1 path ax effects

Chapter 10

解剖一幅图

Book_1《编程不难》 | 鸢尾花书:从加减乘除到机器学习

代码来源:https://matplotlib.org/stable/gallery/showcase/anatomy.html

import matplotlib.pyplot as plt
import numpy as np

from matplotlib.patches import Circle
from matplotlib.patheffects import withStroke
from matplotlib.ticker import AutoMinorLocator, MultipleLocator
royal_blue = [0, 20/256, 82/256]


# make the figure

np.random.seed(19680801)

X = np.linspace(0.5, 3.5, 100)
Y1 = 3+np.cos(X)
Y2 = 1+np.cos(1+X/0.75)/2
Y3 = np.random.uniform(Y1, Y2, len(X))
fig = plt.figure(figsize=(7.5, 7.5))
ax = fig.add_axes([0.2, 0.17, 0.68, 0.7], aspect=1)

ax.xaxis.set_major_locator(MultipleLocator(1.000))
ax.xaxis.set_minor_locator(AutoMinorLocator(4))
ax.yaxis.set_major_locator(MultipleLocator(1.000))
ax.yaxis.set_minor_locator(AutoMinorLocator(4))
ax.xaxis.set_minor_formatter("{x:.2f}")

ax.set_xlim(0, 4)
ax.set_ylim(0, 4)

ax.tick_params(which='major', width=1.0, length=10, labelsize=14)
ax.tick_params(which='minor', width=1.0, length=5, labelsize=10,
               labelcolor='0.25')

ax.grid(linestyle="--", linewidth=0.5, color='.25', zorder=-10)

ax.plot(X, Y1, c='C0', lw=2.5, label="Blue signal", zorder=10)
ax.plot(X, Y2, c='C1', lw=2.5, label="Orange signal")
ax.plot(X[::3], Y3[::3], linewidth=0, markersize=9,
        marker='s', markerfacecolor='none', markeredgecolor='C4',
        markeredgewidth=2.5)

ax.set_title("Anatomy of a figure", fontsize=20, verticalalignment='bottom')
ax.set_xlabel("x Axis label", fontsize=14)
ax.set_ylabel("y Axis label", fontsize=14)
ax.legend(loc="upper right", fontsize=14)


# Annotate the figure

def annotate(x, y, text, code):
    # Circle marker
    c = Circle((x, y), radius=0.15, clip_on=False, zorder=10, linewidth=2.5,
               edgecolor=royal_blue + [0.6], facecolor='none',
               path_effects=[withStroke(linewidth=7, foreground='white')])
    ax.add_artist(c)

    # use path_effects as a background for the texts
    # draw the path_effects and the colored text separately so that the
    # path_effects cannot clip other texts
    for path_effects in [[withStroke(linewidth=7, foreground='white')], []]:
        color = 'white' if path_effects else royal_blue
        ax.text(x, y-0.2, text, zorder=100,
                ha='center', va='top', weight='bold', color=color,
                style='italic', fontfamily='monospace',
                path_effects=path_effects)

        color = 'white' if path_effects else 'black'
        ax.text(x, y-0.33, code, zorder=100,
                ha='center', va='top', weight='normal', color=color,
                fontfamily='monospace', fontsize='medium',
                path_effects=path_effects)


annotate(3.5, -0.13, "Minor tick label", "ax.xaxis.set_minor_formatter")
annotate(-0.03, 1.0, "Major tick", "ax.yaxis.set_major_locator")
annotate(0.00, 3.75, "Minor tick", "ax.yaxis.set_minor_locator")
annotate(-0.15, 3.00, "Major tick label", "ax.yaxis.set_major_formatter")
annotate(1.68, -0.39, "xlabel", "ax.set_xlabel")
annotate(-0.38, 1.67, "ylabel", "ax.set_ylabel")
annotate(1.52, 4.15, "Title", "ax.set_title")
annotate(1.75, 2.80, "Line", "ax.plot")
annotate(2.25, 1.54, "Markers", "ax.scatter")
annotate(3.00, 3.00, "Grid", "ax.grid")
annotate(3.60, 3.58, "Legend", "ax.legend")
annotate(2.5, 0.55, "Axes", "fig.subplots")
annotate(4, 4.5, "Figure", "plt.figure")
annotate(0.65, 0.01, "x Axis", "ax.xaxis")
annotate(0, 0.36, "y Axis", "ax.yaxis")
annotate(4.0, 0.7, "Spine", "ax.spines")

# frame around figure
fig.patch.set(linewidth=4, edgecolor='0.5')
plt.show()

png

标签:Ch10,01,color,annotate,set,Bk1,path,ax,effects
From: https://www.cnblogs.com/tianpan2019/p/18307232

相关文章

  • PC XMind v24.01.14362 解锁版安装教程 (全球领先的商业思维导图软件)
    前言XMind是一款专业的全球领先的商业思维导图软件,在国内使用广泛,拥有强大的功能、包括思维管理、商务演示、与办公软件协同工作等功能。它采用全球先进的EclipseRCP软件架构,是集思维导图与头脑风暴于一体的可视化思考工具,能用来捕捉想法、理清思路、管理复杂信息并促进团队协......
  • 大语言模型无法理解链表 Large Language Models Fails to Understand Chained Table[u
    大模型可以翻转链表,但是只能翻转单个元素链表。一但牵扯到分组操作,就不会了。Case:以K个元素为一组位翻转链表,每一组内部元素顺序不变。ReversethechainedtableingroupofKelements,don'tchangetheorderineachgroup. Handwritten: 1classNode():2......
  • 【python零基础入门到就业】011、一文读懂python中的标识符(超详细)
    文章目录Python中的标识符(超详细)1.什么是标识符?示例:标识符示意图2.标识符的命名规则2.1基本规则示例:非法示例:2.2常见Python关键字标识符命名规则示意图3.标识符的命名规范3.1变量命名示例:3.2函数命名示例:3.3类命名示例:命名规范示意图4.常见的命名错误4.1混......
  • 人生低谷来撸C#--011命名空间
    命名空间 提供一种让一组名称与其他名称分隔开的方式。在一个命名空间中声明的类的名称与另一个命名空间中声明的相同的类的名称不冲突。我们举一个计算机系统中的例子,一个文件夹(目录)中可以包含多个文件夹,每个文件夹中不能有相同的文件名,但不同文件夹中的文件可以重名。如......
  • Windows Server 2012 R2 Update 出现错误 80072EFE
    解决方案一错误代码80072EFE表示与服务器的连接异常终止。请确保没有防火墙规则或代理阻止Microsoft下载URL。您还可以尝试以下操作:单击“开始”,然后单击“运行”。在“打开”框中键入cmd在命令提示符下键入“netstopwuauserv”(不带引号),然后按Enter。删除(或放......
  • vue基础day01(MVVM、绑定、事件、结构模板)
    vue基础一、什么是vue构建用户界面的渐进式框架,采用自底向上逐层应用开发核心理念:数据驱动视图,组件化开发二、框架和库的区别框架:一套完整的解决方案,对项目的侵入性较大,项目如果需要更换框架,需要重新架构整个项目库:提供了一个小的功能,对项目的侵入性较小,如果某个库无......
  • eclipse免安装版64位 2018版本
    前言Eclipse是一个开放源代码的、基于Java的可扩展开发平台。就其本身而言,它只是一个框架和一组服务,用于通过插件组件构建开发环境。幸运的是,Eclipse附带了一个标准的插件集,包括Java开发工具(JavaDevelopmentKit,JDK)。虽然大多数用户很乐于将Eclipse当作Java集成开发......
  • 题解|2024暑期牛客多校01
    【原文链接】太菜了就先挂4题,其他的写出来了再回来补QwQA.ABitCommon组合数学题目大意题目概括:给定两个整数nnn和m......
  • [[BJWC2012] 冻结]
    [BJWC2012]冻结题目大意在能有\(k\)次机会使得某些道路变为其\(\frac{1}{2}\)长度的情况下,求\(1\)到\(n\)的最短路做法其实就是分层最短路的模板题,有\(k\)次机会减少,那么对于一个点来说就有可能是在这前使用了\(0\)~\(k\)次减少的机会到达的,每个点都有\(k\)个分身,故要建\(k+1......
  • 代码随想录算法训练营第十四天 | 226.翻转二叉树、101. 对称二叉树、 104.二叉树的最
    226.翻转二叉树题目:.-力扣(LeetCode)思路:前序遍历代码:classSolution{public:TreeNode*invertTree(TreeNode*root){if(root!=NULL){swap(root->left,root->right);invertTree(root->left);invertTree(root->right);}......