首页 > 其他分享 >Chapter5 注解

Chapter5 注解

时间:2023-04-14 10:46:27浏览次数:37  
标签:plt Chapter5 annotate 代表 fraction 注解 x0 data

注解


import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-3,3,50)
y = 2*x+1

plt.figure(num=1,figsize=(8,5),)
plt.plot(x,y,)

ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data',0))

# 设置点的坐标
x0 = 1
y0 = 2*x0+1
# scatter 用于绘制散点图(绘制一个点或多个点)
# s代表点的大小,color代表点的颜色
plt.scatter(x0,y0,s=50,color='blue')
# [x0,x0][y0,0]代表通过x0,y0和x0,0两点来生成一条直线
# k-- 代表颜色时黑色,其样式为虚线
# lw代表线宽度
plt.plot([x0,x0],[y0,0],'k--',lw=2.5)

# 如何使用annotations?

# method 1
#####################
# 第一个参数代表内容
# 第二个参数代表要解释的点
# 第三个参数代表解释的坐标点以data格式为基准。(类似于移动坐标轴的data)
# 第四个参数代表要解释的文本所显示的位置
# 第五个参数一般配合第四个参数使用,代表文本所显示的位置,以offset points 格式为基准。
# 代表文本以解释的点为基准,在该点的基础上x偏移+30,y偏移-30。
# 注意这里偏移量+30 -30 并不是以data格式为基准,因此不是在坐标轴上进行平移
# 第六个参数代表文字大小
# 第七个参数代表设置箭头(用箭头指向要解释的点)
# 设置箭头需要使用dict来定义箭头格式(arrowstyle代表使用哪种格式的箭头,connectionstyle代表该箭头的弧度样式和圆角)
plt.annotate(r'$2x+1=%s$' % y0,xy=(x0,y0),xycoords='data',xytext=(+30,-30),textcoords='offset points',
             fontsize=16,arrowprops=dict(arrowstyle='->',connectionstyle='arc3,rad=0.2'))

# method 2
#####################
# 第一个,二个参数代表文本显示的位置,data格式
# 第三个参数代表显示的内容 \mu\ 代表μ、sigma_i 代表σ且下标为i
# 第四个参数代表字体样式,以字典形式给出。

plt.text(-3.7,3,r'$This\ is\ the\ some\ text.\ \mu\ \sigma_i\ \alpha_t$',
         fontdict={'size':16,'color':'r'})
plt.show()
                           

img

    import matplotlib.pyplot as plt
    # plt.annotate(str, xy=data_point_position, xytext=annotate_position, 
    #              va="center",  ha="center", xycoords="axes fraction", 
    #              textcoords="axes fraction", bbox=annotate_box_type, arrowprops=arrow_style)
    # str是给数据点添加注释的内容,支持输入一个字符串
    # xy=是要添加注释的数据点的位置
    # xytext=是注释内容的位置
    # bbox=是注释框的风格和颜色深度,fc越小,注释框的颜色越深,支持输入一个字典
    # va="center",  ha="center"表示注释的坐标以注释框的正中心为准,而不是注释框的左下角(v代表垂直方向,h代表水平方向)
    # xycoords和textcoords可以指定数据点的坐标系和注释内容的坐标系,通常只需指定xycoords即可,textcoords默认和xycoords相同 axes fraction 代表原点在xy轴的左下角
    figure fraction 代表原点在整个figure的左下角
    # arrowprops可以指定箭头的风格支持,输入一个字典
    # plt.annotate()的详细参数可用__doc__查看,如:print(plt.annotate.__doc__)

import matplotlib.pyplot as plt

# facecolor 代表背景颜色
fig = plt.figure(1,facecolor='white')
# 代表清空图像
fig.clf()
plt.annotate('a decision node',(0.1,0.5),(0.5,0.1),va='center',ha='center',
             xycoords='axes fraction', textcoords='axes fraction', bbox=dict(boxstyle='sawtooth',fc='0.8'),arrowprops=dict(arrowstyle='<-'))
plt.show()

img

import matplotlib.pyplot as plt

# facecolor 代表背景颜色
fig = plt.figure(1,facecolor='white')
# 代表清空图像
fig.clf()
# 更改了注解的坐标基准
plt.annotate('a decision node',(0.1,0.5),(0.5,0.1),va='center',ha='center',
             xycoords='axes fraction', textcoords='figure fraction', bbox=dict(boxstyle='sawtooth',fc='0.8'),arrowprops=dict(arrowstyle='<-'))
plt.show()

img

    注:本博客的部分内容来自于:https://blog.csdn.net/watermelon12138/article/details/88375823

标签:plt,Chapter5,annotate,代表,fraction,注解,x0,data
From: https://www.cnblogs.com/gao79135/p/17317581.html

相关文章

  • Spring IOC容器注解大全—基于Java的容器配置
    本节介绍了如何在你的Java代码中使用注解来配置Spring容器。它包括以下主题。基本概念:@Bean 和 @Configuration通过使用 AnnotationConfigApplicationContext 实例化Spring容器使用 @Bean 注解使用 @Configuration 注解构建基于Java的配置Bean定义配置PropertySource 抽象......
  • mvc纯注解驱动
    1、自定义servlet容器初始化配置类,加载SpringMVC核心配置类,代替web.xmlimportorg.springframework.web.context.WebApplicationContext;importorg.springframework.web.context.support.AnnotationConfigWebApplicationContext;importorg.springframework.web.filter.Chara......
  • Springmvc常用注解参数与返回值
    1.常用注解1.1.@RequestMapping@RequestMapping注解是一个用来处理请求地址映射的注解,可用于映射一个请求或一个方法,可以用在类或方法上。标注在方法上用于方法上,表示在类的父路径下追加方法上注解中的地址将会访问到该方法@ControllerpublicclassHelloController{......
  • SpringBoot启动后获取特定注解的Bean实例代码(转)
    来自:https://zhuanlan.zhihu.com/p/375973197本文研究的主要是Spring启动后获取所有拥有特定注解的Bean,具体如下。最近项目中遇到一个业务场景,就是在Spring容器启动后获取所有的Bean中实现了一个特定接口的对象,第一个想到的是ApplicationContextAware,在setApplicationContext中......
  • springboot中获取指定包下的包含某个注解的全部类(转)
    来自:https://www.cnblogs.com/lexiaoyao1995/p/13943784.html需求获取spring项目里的带有某个注解的全部类难点需要扫描指定包路径下的类,同时也要扫描其下所有子包思路可以自己实现,推荐使用spring的工具类代码packagecom.example.demo;importcom.example.demo.annos......
  • spring声明式事务(注解)
     xml中开启注解驱动:  ......
  • Jackson常用注解
    目录Jackson常用注解序列化注解@com.fasterxml.jackson.annotation.JsonAnyGetter@com.fasterxml.jackson.annotation.JsonFormat@com.fasterxml.jackson.annotation.JsonGetter@com.fasterxml.jackson.annotation.JsonInclude@com.fasterxml.jackson.annotation.JsonIncludePrope......
  • 聊聊如何运用JAVA注解处理器(APT)
    什么是APTAPT(AnnotationProcessingTool)它是Java编译期注解处理器,它可以让开发人员在编译期对注解进行处理,通过APT可以获取到注解和被注解对象的相关信息,并根据这些信息在编译期按我们的需求生成java代码模板或者配置文件(比如SPI文件或者spring.fatories)等。APT获取注解及生成代......
  • 【Spring boot】 @Value注解
    一、不通过配置文件的注入属性1.1注入普通字符串直接附在属性名上,在Bean初始化时,会赋初始值@Value("normal")privateStringnormal;1.2注入java系统变量@Value("#{systemProperties['os.name']}")privateStringsystemPropertiesName;//注入操作系统属性1.3注......
  • Android Debug (调试)注解处理器
     1.addremotedebugconfiguration2.copyjvmoptions:(-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005),andpasteittogradle.propertiesfile.  3.thenclickdebugbuttontoattachlocalhost:5005,expandthegradletasklist......