python matplotlib 注释文本箭头简单代码示例

yipeiwu_com6年前Python基础

注释文本箭头

结果展示:

完整代码示例:

import numpy as np
import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(5, 5))
ax.set_aspect(1)

x1 = -1 + np.random.randn(100)
y1 = -1 + np.random.randn(100)
x2 = 1. + np.random.randn(100)
y2 = 1. + np.random.randn(100)

ax.scatter(x1, y1, color="r")
ax.scatter(x2, y2, color="g")

bbox_props = dict(boxstyle="round", fc="w", ec="0.5", alpha=0.9)
ax.text(-2, -2, "Sample A", ha="center", va="center", size=20,
    bbox=bbox_props)
ax.text(2, 2, "Sample B", ha="center", va="center", size=20,
    bbox=bbox_props)


bbox_props = dict(boxstyle="rarrow", fc=(0.8, 0.9, 0.9), ec="b", lw=2)
t = ax.text(0, 0, "Direction", ha="center", va="center", rotation=45,
      size=15,
      bbox=bbox_props)

bb = t.get_bbox_patch()
bb.set_boxstyle("rarrow", pad=0.6)

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

plt.show()

总结

以上就是本文关于python matplotlib 注释文本箭头简单代码示例的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站:

matplotlib绘制动画代码示例

python+matplotlib绘制简单的海豚(顶点和节点的操作)

Python通过matplotlib画双层饼图及环形图简单示例

如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

相关文章

Python语法分析之字符串格式化

前序 There should be one - and preferably only one - obvious way to do it. ———— the Zen of Pyt...

对Pytorch神经网络初始化kaiming分布详解

对Pytorch神经网络初始化kaiming分布详解

函数的增益值 torch.nn.init.calculate_gain(nonlinearity, param=None) 提供了对非线性函数增益值的计算。 增益值gain是一个...

python requests模拟登陆github的实现方法

python requests模拟登陆github的实现方法

1. Cookie 介绍 HTTP 协议是无状态的。因此,若不借助其他手段,远程的服务器就无法知道以前和客户端做了哪些通信。Cookie 就是「其他手段」之一。 Cookie 一个典型的...

python按照多个条件排序的方法

对tuple进行排序,先按照第一个元素升序,如果第一个元素相同,再按照第二个元素降序排列。 L = [(12, 12), (34, 13), (32, 15), (12, 24),...

Python实现将xml导入至excel

Python实现将xml导入至excel

最近在使用Testlink时,发现导入的用例是xml格式,且没有合适的工具转成excel格式,xml使用excel打开显示的东西也太多,网上也有相关工具转成csv格式的,结果也不合人意。...