matplot--annotate()函数

函数功能:添加图形内容细节的指向型注释文本。

s:str, 注释信息内容

xy:(float,float), 箭头点所在的坐标位置

xytext:(float,float), 注释内容的坐标位置

weight: str or int, 设置字体线型,其中字符串从小到大可选项有{‘ultralight’, ‘light’, ‘normal’, ‘regular’, ‘book’, ‘medium’, ‘roman’, ‘semibold’, ‘demibold’, ‘demi’, ‘bold’, ‘heavy’, ‘extra bold’, ‘black’}

color: str or tuple, 设置字体颜色 ,单个字符候选项{‘b’, ‘g’, ‘r’, ‘c’, ‘m’, ‘y’, ‘k’, ‘w’},也可以’black’,'red’等,tuple时用[0,1]之间的浮点型数据,RGB或者RGBA, 如: (0.1, 0.2, 0.5)、(0.1, 0.2, 0.5, 0.3)等

arrowprops #箭头参数,参数类型为字典dict。参数如下:

width:the width of the arrow in points 箭头的宽度(以点为单位)
headwidth: the width of the base of the arrow head in points 箭头底部以点为单位的宽度 。
headlength: the length of the arrow head in points 箭头的长度(以点为单位) 。
shrink:fraction of total length to ‘shrink’ from both ends 总长度的一部分,从两端“收缩”。
facecolor:箭头颜色

bbox:dict,为注释文本添加边框,其key有①boxstyle,其格式类似’round,pad=0.5’,其可选项如下:
在这里插入图片描述
②facecolor(可简写为fc)设置背景颜色
③ edgecolor(可简写为ec)设置边框线条颜色
④lineweight(可简写为lw)设置边框线型粗细
⑤alpha设置透明度,[0,1]之间的小数,0代表完全透明,即类似③颜色设置无效。
具体看下面例子

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 100)
y = np.sin(x)

plt.figure(figsize=(12, 9))
plt.plot(x, y, linestyle='-', color='blue')

 
plt.annotate(s='local min', 
             xy=(3*np.pi/2, -1.0),
             xytext=(3*np.pi/2, -0.5), 
             weight='bold', 
             color='aqua',
             arrowprops=dict(fc='black', shrink=0.05),
             bbox=dict(boxstyle='round, pad=0.2', fc='yellow', ec='k',lw=1 ,alpha=0.2),
             ha='center',
             fontsize=12) #ha='center'表示local min这串文字处于箭头中心(horizontalalignment:水平对齐方式 ,参数:[ ‘center’ | ‘right’ | ‘left’ ])

在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue Image Annotate 是一个基于 Vue3 和 Konva.js 的图像标注组件库,可以用于在图片上进行标注。下面是一个简单的示例,演示如何使用 Vue Image Annotate 进行图像标注: 首先,安装 vue-image-annotate: ```bash npm install vue-image-annotate ``` 然后,在你的 Vue 组件中导入并使用 Vue Image Annotate: ```vue <template> <div> <vue-image-annotate ref="annotate" :image-url="imageUrl" @annotation-updated="onAnnotationUpdated"></vue-image-annotate> <button @click="saveAnnotations">保存标注</button> </div> </template> <script> import VueImageAnnotate from 'vue-image-annotate'; export default { components: { VueImageAnnotate, }, data() { return { imageUrl: 'path/to/your/image.jpg', }; }, methods: { onAnnotationUpdated(annotations) { // 在标注更新时触发此回调函数 console.log('标注更新:', annotations); }, saveAnnotations() { const annotations = this.$refs.annotate.getAnnotations(); // 将标注数据保存到后端或本地存储等 console.log('保存标注:', annotations); }, }, }; </script> ``` 在上述示例中,我们首先导入了 `vue-image-annotate` 组件,并在模板中使用了 `<vue-image-annotate>` 标签来显示图像和进行标注。通过 `:image-url` 属性可以指定要显示的图片路径。`@annotation-updated` 事件会在标注更新时触发,你可以在回调函数中处理标注数据。点击 "保存标注" 按钮时,我们调用 `getAnnotations` 方法获取当前的标注数据。 这只是一个简单的示例,你可以进一步自定义和扩展 Vue Image Annotate 来满足你的具体需求。更多用法和配置选项,你可以参考 Vue Image Annotate 的官方文档。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值