【问题标题】:Annotate underbrace(brackets) between points on the x-axis在 x 轴上的点之间注释下括号(括号)
【发布时间】:2021-05-31 21:58:20
【问题描述】:

如何获取此图并注释或直接添加在每个单词之间添加一些文本的下括号,然后我假设将 x-label 稍微向下移动以使其清晰可见。

创建示例:

起始代码:

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();

【问题讨论】:

    标签: python matplotlib annotate


    【解决方案1】:

    注解的坐标是轴设置的,位置是手动设置的。

    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))
    

    【讨论】:

      猜你喜欢
      • 2020-08-17
      • 2021-01-17
      • 1970-01-01
      • 2016-10-03
      • 2020-08-09
      • 1970-01-01
      • 2014-11-26
      • 1970-01-01
      相关资源
      最近更新 更多