小编Mau*_*ice的帖子

如何将python代码行分配给变量

我打算在python中做这样的事情:

plt.plot(xval_a_target, q_prof_target, label=r"target", color=target_color, ls=target_style, linewidth=lwidth)
Run Code Online (Sandbox Code Playgroud)

我正在以这种方式创建许多不同的图,并希望将后一部分分配给变量:

target_plot_style = """label=r"target", color=target_color, ls=target_style, linewidth=lwidth"""
Run Code Online (Sandbox Code Playgroud)

为了将绘图线缩短为: plt.plot(xval_a_target, q_prof_target, eval(target_plot_style),我尝试使用eval和exec进行了尝试,但是它不起作用。有没有简单的方法可以做到这一点?

python matplotlib

0
推荐指数
1
解决办法
60
查看次数

标签 统计

matplotlib ×1

python ×1