注释X轴上各点之间的底圈(括号)

2024-05-17 07:15:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我怎样才能画出这个图并注释,或者直接添加一个在每个单词之间添加一些文本的底栏,然后我假设通过稍微向下移动x标签使其易读

创建的示例:

enter image description here

起始代码:

import numpy as np
import matplotlib.pyplot as plt

# Array of values
values = np.array([[1,2,3], [1,2,3]])

# Line plot
fig, ax = plt.subplots()
plt.plot(values[0,:], values[1,:], 'bo-',label='$P_{1}$')


# Annotate the points of interest
ax.annotate('s', xy=(1.5, 0), xytext=(1.5, -0.8),
            fontsize=1.5, ha='center', va='bottom',
            bbox=dict(boxstyle='square', fc='white'),
            arrowprops=dict(arrowstyle='-[, widthB=45.0, lengthB=1.5', lw=2.0))

ax.annotate('t-s', xy=(2.5, 0), xytext=(2.5, -0.8),
            fontsize=1.5, ha='center', va='bottom',
            bbox=dict(boxstyle='square', fc='white'),
            arrowprops=dict(arrowstyle='-[, widthB=43.0, lengthB=2.5', lw=2.0))

plt.legend();

enter image description here


Tags: ofimportplotasnppltaxdict
1条回答
网友
1楼 · 发布于 2024-05-17 07:15:31

注释的坐标由轴设置,位置由手动设置

ax.annotate('s', xy=(0.275, -0.15), xytext=(0.275, -0.35),
            fontsize=14, ha='center', va='bottom', xycoords='axes fraction', 
            bbox=dict(boxstyle='square', fc='0.8'),
            arrowprops=dict(arrowstyle='-[, widthB=5.0, lengthB=.5', lw=2.0))

ax.annotate('t-s', xy=(0.725, -0.15), xytext=(0.725, -0.35),
            fontsize=14, ha='center', va='bottom', xycoords='axes fraction', 
            bbox=dict(boxstyle='square', fc='0.8'),
            arrowprops=dict(arrowstyle='-[, widthB=5.0, lengthB=.5', lw=2.0))

enter image description here

相关问题 更多 >