如何使用 sympy 图的标记参数?
sympy plot
命令有一个 markers
参数:
markers :指定所需标记类型的字典列表。字典中的键应该相当于 matplotlib 的plot()函数的参数以及与标记相关的关键字参数。
如何使用markers
参数?我失败的尝试范围从
from sympy import *
x = symbols ('x')
plot (sin (x), markers = 'o')
到
plot (sin (x), markers = list (dict (marker = 'o')))
The sympy plot
command has a markers
parameter:
markers : A list of dictionaries specifying the type the markers required. The keys in the dictionary should be equivalent to the arguments of the matplotlib's plot() function along with the marker related keyworded arguments.
How do I use the markers
parameter? My failed attempts range from
from sympy import *
x = symbols ('x')
plot (sin (x), markers = 'o')
to
plot (sin (x), markers = list (dict (marker = 'o')))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不错的发现!
文档并没有把事情说清楚。深入研究源代码,会导致 图中的这些行.py:
所以,sympy 只是调用 matplotlib 的 plot 其中:
args
键字典作为位置参数由于 matplotlib 的
plot
允许使用各种各样的参数,因此这里都支持它们。它们的主要目的是在绘图上显示额外的标记(您需要给出它们的位置)。示例:
这些内容会转换为:
PS:源代码显示了带有注释、矩形和填充的字典的类似方法(使用
plt.fill Between()
):Nice find!
The documentation doesn't make things clear. Diving into the source code, leads to these lines in plot.py:
So, sympy just calls matplotlib's plot with:
args
key of the dictionary as positional parametersAs matplotlib's
plot
allows a huge variety of parameters, they all are supported here. They are primarily meant to show extra markers onto the plot (you need to give their positions).An example:
These get converted to:
PS: The source code shows a similar approach for dictionaries with annotations, rectangles and fills (using
plt.fillbetween()
):(更新使用@cards建议(在评论中)和这篇文章。
您可以使用 Matplotlib 后端将标记直接添加到轴。
此解决方案还使用标记更新图例。
(Updated using @cards suggestion (in comments) and this post.
You can add markers directly to the axis using the Matplotlib backend.
This solution also updates the legend with the markers.