You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用SymPy的symplot绘图时如何为各曲线设置t=-4等对应名称

解决方案

你只需要调整symplot的传参格式即可:SymPy的绘图函数支持传入(表达式, 系列标签)格式的元组,为每条曲线单独指定图例名称,同时添加show_legend=True参数开启图例显示即可实现需求。

修改后的完整代码如下:

from sympy import symbols
from sympy.plotting import plot as symplot
# u(x, t) 已预先定义完成
symplot(
    (u(x, -4), 't = -4'),
    (u(x, -2), 't = -2'),
    (u(x, 0), 't = 0'),
    (u(x, 2), 't = 2'),
    (u(x, 4), 't = 4'),
    show_legend=True
)

如果需要调整图例的显示位置,可以额外添加legend_loc参数,可选值与matplotlib图例位置参数完全一致,例如legend_loc='upper right'指定图例显示在右上角。


内容的提问来源于stack exchange,提问作者taro_eng

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 02:36:04