Using matplotlib patches in julia
Using the output from a calculation in julia (working in IJulia), I would like to draw a figure using the matplotlib patch module (via the Steven Johnson PyCall
and Steven Johnson packages PyPlot
). I have read several related stackoverflow posts but I cannot find a minimal working example. Can anyone post a simple example? Anything that depicts a rectangle or an ellipse?
Here's a python example that works:
#!/usr/local/bin/python3
import matplotlib.pyplot
import matplotlib.patches
cfig = matplotlib.pyplot.figure()
c = cfig.add_subplot(111)
c.set_aspect("equal")
p = matplotlib.patches.Circle([0.5,0.5],0.40,fc="blue",ec="red",linewidth=5,zorder=0)
c.add_patch(p)
cfig.savefig("circle.pdf",bbox_inches="tight")
My attempt at the same in Julia throws itself at the subtitle
using PyPlot using PyCall @pyimport matplotlib.patches as patches cfig = figure() c = cfig.add_subplot(111)
What gives:
type Figure has no field add_subplot
while loading In[19], in expression starting on line 4
+3
source to share
1 answer
OK, thanks to the link jverzani, I was able to put together a working example. I am still a little wobbly on the syntax in Julia to tweak all the plot options.
using PyPlot
using PyCall
@pyimport matplotlib.patches as patch
cfig = figure()
ax = cfig[:add_subplot](1,1,1)
ax[:set_aspect]("equal")
c = patch.Circle([0.5,0.5],0.4,fc="blue",ec="red",linewidth=.5,zorder=0)
ax[:add_artist](c)
cfig[:savefig]("circle.png")
+2
source to share