Reputation: 334
Using the output from a computation in julia (working in IJulia), I'd like to draw a figure using matplotlib's patches module (via Steven Johnson's PyCall
and PyPlot
packages). I've read several related posts on stackoverflow, but I can't seem to get a minimum working example. Could somebody post a simple example? Say something that plots 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 thing in Julia stalls at the subplot
using PyPlot
using PyCall
@pyimport matplotlib.patches as patches
cfig = figure()
c = cfig.add_subplot(111)
Which yields:
type Figure has no field add_subplot
while loading In[19], in expression starting on line 4
Upvotes: 4
Views: 2033
Reputation: 334
OK, thanks to jverzani's link, I was able to piece together a working example. I'm still a little shaky on the syntax in Julia for setting all the options for the plot.
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")
Upvotes: 4