在pylab模式下绘制矩形(add_patch) [英] Draw rectangle (add_patch) in pylab mode

查看:62
本文介绍了在pylab模式下绘制矩形(add_patch)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在pylab模式下使用IPython(所有功能都在指尖),并且想要注释某些绘图,比如说 plot([1,3,2])具有矩形((1,1),1,1)

I'm using IPython in pylab mode (all functions at fingertip), and wanted to annotate certain plot, lets say plot([1,3,2]) with rectangle Rectangle((1,1),1,1)

如何在pylab模式下绘制一个简单的矩形,即不使用图形,轴,子图...而是以最简单的方式引用刚刚创建的图

How can I draw a simple rectangle in this pylab mode, that is without using figure, axes, subplots... but reference just created plot in easiest possible way

推荐答案

在这种pylab模式下,即不使用图形、轴、子图

in this pylab mode, that is without using figure, axes, subplots

pylab框架中也存在变形,轴和子图.如果我使用的是 pylab 界面,我只需在其中抛出一个 subplot(111),然后使用 sp.add_patch(Rectangle(etc)).但是您也可以使用 gca() gcf()来获取当前轴/图形:

Figues, axes, and subplots exist in the pylab framework too. If I were using the pylab interface, I'd simply throw a subplot(111) in there and then use sp.add_patch(Rectangle(etc)). But you can also grab the current axes/figure using gca() and gcf():

>>> from pylab import *
>>> plot([1,3,2])
[<matplotlib.lines.Line2D object at 0x102bc8950>]
>>> gca()
<matplotlib.axes.AxesSubplot object at 0x102790cd0>
>>> gca().add_patch(Rectangle((1,1),1,1))
<matplotlib.patches.Rectangle object at 0x102790510>
>>> savefig("rect.png")

pylab 方法对于非常基本的任务来说足够简单,但不能很好地扩展到更复杂的任务.

The pylab approach is simple enough for very basic tasks, but doesn't scale as well up to more complex ones.

这篇关于在pylab模式下绘制矩形(add_patch)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆