通过元素 matplotlib.pyplot 构建绘图?
有没有办法逐个元素地构建情节?例如,在 R 中,您可以执行类似的操作,
plot.new() ## start a new plot
plot.window(c(0,10),c(0,10)) ## set data limits
lines(1:10) ## draw a line
points(1:10) ## draw points
axis(1) ## draw x axis
axis(2) ## draw y axis
box() ## draw box around figure
到目前为止,我在 pyplot 中知道的所有函数都从绘制包含所有元素的图形开始,然后隐藏、删除或修改它们。
Is there a way to build up a plot element-by-element? For instance, in R you can do something like
plot.new() ## start a new plot
plot.window(c(0,10),c(0,10)) ## set data limits
lines(1:10) ## draw a line
points(1:10) ## draw points
axis(1) ## draw x axis
axis(2) ## draw y axis
box() ## draw box around figure
So far all the functions I know in pyplot begins with plotting a graphic with all elements and either hiding, removing, or modifying them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你可以控制情节的所有方面,但这并不简单。您必须从 matplotlib.pyplot.axes 对象开始,然后添加内容。例如,使用以下命令添加线条:matplotlib.pyplot.axhline() 和 matplotlib.pyplot.axvline()。我发现从某事开始更容易。另一个好技巧是检查示例库。通常会给你一些非常接近你想要的东西。
Yes, you can control all the aspects of a plot, but it is not straightforward. You have to start from a matplotlib.pyplot.axes object, and add stuff. For example, lines are added with: matplotlib.pyplot.axhline() and matplotlib.pyplot.axvline(). I find easier to start from something. Another good trick is to check the gallery of examples. Than usually gives you something pretty close to what you want.