Draw rectangle (add_patch) in pylab mode

前端 未结 1 587
抹茶落季
抹茶落季 2021-01-11 19:33

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条回答
  •  一生所求
    2021-01-11 19:36

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

    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])
    []
    >>> gca()
    
    >>> gca().add_patch(Rectangle((1,1),1,1))
    
    >>> savefig("rect.png")
    

    line with rectangle

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

    0 讨论(0)
提交回复
热议问题