首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Matplotlib中的内联标签

Matplotlib中的内联标签
EN

Stack Overflow用户
提问于 2013-06-08 03:59:23
回答 2查看 142.8K关注 0票数 119

在Matplotlib中,创建一个图例(example_legend(),下图)并不太难,但我认为将标签放在正在绘制的曲线上(如example_inline()中,下图)会更好。这可能非常麻烦,因为我必须手动指定坐标,并且,如果我重新格式化绘图,我可能必须重新定位标签。有没有办法在Matplotlib中自动生成曲线上的标签?能够以与曲线角度相对应的角度调整文本方向的加分。

代码语言:javascript
复制
import numpy as np
import matplotlib.pyplot as plt

def example_legend():
    plt.clf()
    x = np.linspace(0, 1, 101)
    y1 = np.sin(x * np.pi / 2)
    y2 = np.cos(x * np.pi / 2)
    plt.plot(x, y1, label='sin')
    plt.plot(x, y2, label='cos')
    plt.legend()

代码语言:javascript
复制
def example_inline():
    plt.clf()
    x = np.linspace(0, 1, 101)
    y1 = np.sin(x * np.pi / 2)
    y2 = np.cos(x * np.pi / 2)
    plt.plot(x, y1, label='sin')
    plt.plot(x, y2, label='cos')
    plt.text(0.08, 0.2, 'sin')
    plt.text(0.9, 0.2, 'cos')

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16992038

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档