【问题标题】:How can I name each graph如何命名每个图表
【发布时间】:2021-11-22 22:00:34
【问题描述】:

enter image description here我想用 sympy 将每个图命名为 't = -4','t = 2',,,,'t = 4'。 我应该添加什么句子来做到这一点。函数 u(x,t) 已经定义好了。

from sympy import symbols
from sympy.plotting import plot as symplot
symplot(u(x,-4),u(x,-2),u(x,0),u(x,2),u(x,4))

【问题讨论】:

    标签: python plot sympy


    【解决方案1】:

    您可以为使用 legend=True 调用的每个函数图使用特定标签,如下所示:

    from sympy import symbols
    from sympy.plotting import plot
    x = symbols('x')
    p1 = plot(x**2, label="first function",show=False, legend=True)
    p2 = plot(x, -x, label="second function",show=False, legend=True)
    p1.extend(p2)  # any other shape can be added to the original using this method. 
    
    p1.show()
    

    它应该是这样的 (example):

    如果你有 p3,那么你可以像使用 p1 和 p2 一样绘制它,然后只需编写 p1.extend(p3) 等...

    【讨论】:

    • 我将您的代码复制并粘贴到我的 jupyter 笔记本上,但我的标签仍然显示 'x**2' 、 'x' 、 '-x' 而不是 'first function'。
    • 如果我没有看到您的代码,我无法给您反馈。在您的问题中分享您的 jupyter notebook 代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    • 2015-10-02
    • 2020-03-31
    • 1970-01-01
    • 1970-01-01
    • 2021-07-02
    • 1970-01-01
    相关资源
    最近更新 更多