# Adding a patch in pyplot

**URL:** https://discourse.julialang.org/t/adding-a-patch-in-pyplot/13343
**Category:** General Usage
**Created:** [August 13, 2018, 5:44am UTC](https://discourse.julialang.org/t/adding-a-patch-in-pyplot/13343 "2018-08-13T05:44:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)
#### Post date: [August 13, 2018, 5:44am UTC](https://discourse.julialang.org/t/adding-a-patch-in-pyplot/13343/1 "2018-08-13T05:44:32Z")

</div>

I’m translating an example i found on the web.

the part I can’t figure out is this

```julia
plt.gca().add_patch(circle)

```

there is a top level method in PyPlot, but that won’t work, because add\_patch is clearly a method as plt.gca() should return the current graphic context.

so then I figured the usual trick might work, i.e.

matplotlib[:gca]

but that doesn’t work either, because the gca key doesn’t exist.

any ideas on how I might do this ?

thank you !

here’s the code so far - ignore gca[:add\_patch]- that doesn’t work

```julia
    xlim(0.0, 0.005)
    ylim(0.0, 0.005)
    grid()
    
    circle = matplotlib[:patches][:Circle]((0.001, 0.001), radius = 0.001, facecolor="b")
    gca[:add_patch](circle)
    show()

```

---

<div class="post-metadata">

### Author: ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)
#### Post date: [August 13, 2018, 6:02am UTC](https://discourse.julialang.org/t/adding-a-patch-in-pyplot/13343/2 "2018-08-13T06:02:08Z")

</div>

aha!  
I was looking at an outdated example. I went to the matplotlib docs and was able to create some code that worked !  
for reference here’s the page:

[https://matplotlib.org/gallery/api/patch\_collection.html#sphx-glr-gallery-api-patch-collection-py](https://matplotlib.org/gallery/api/patch_collection.html#sphx-glr-gallery-api-patch-collection-py)

```julia
using PyPlot

fig, ax = subplots()
xlim(0.0, 0.005)
ylim(0.0, 0.005)
grid()
        
circle1 = matplotlib[:patches][:Circle]((0.001, 0.001), radius = 0.001, facecolor="b")
circle2 = matplotlib[:patches][:Circle]((0.003, 0.003), radius = 0.001, facecolor="r")
p = matplotlib[:collections][:PatchCollection]([circle1, circle2])
ax[:add_collection](p)
show()

```

just a couple of problems.

the second circle color is still blue. i think this may be a problem with the use of collections. it looks like maybe I need to perform a separate operation to set colors.

also I get the following warning when i run the code:

```julia
┌ Warning: The start/next/done iteration protocol is deprecated. Implement `iterate(::PyCall.PyDict{Symbol,PyCall.PyObject,true})`.
│ caller = ip:0x0
└ @ Core :-1

```

I’m running 0.7, not 1.0, maybe it’s a 0.7 thing ?

---

<div class="post-metadata">

### Author: ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)
#### Post date: [August 13, 2018, 11:50am UTC](https://discourse.julialang.org/t/adding-a-patch-in-pyplot/13343/3 "2018-08-13T11:50:23Z")

</div>

Youre correct - the warning is a deprecation warning for moving from 0.6 to 1.0 (that’s what the 0.7 release is for), I’m guessing for PyPlot. From what I can tell, it hasn’t been updated to support 1.0 yet, though there’s a bunch of activity on the front.
