Skip to content

Commit ac1827e

Browse files
committed
export and document using3D() function to ensure mplot3d is loaded (fixes #351)
1 parent 9b8f618 commit ac1827e

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ If no Julia graphics backend is available when PyPlot is imported, then
174174
### Choosing a Python GUI toolkit
175175

176176
Only the [Tk](http://www.tcl.tk/), [wxWidgets](http://www.wxwidgets.org/),
177-
[GTK+](http://www.gtk.org/) (version 2 or 3), and [Qt](http://qt-project.org/) (version 4 or 5; via the PyQt5,
177+
[GTK+](http://www.gtk.org/) (version 2 or 3), and [Qt](http://qt-project.org/) (version 4 or 5; via the PyQt5,
178178
[PyQt4](http://wiki.python.org/moin/PyQt4) or
179179
[PySide](http://qt-project.org/wiki/PySide)), Python GUI backends are
180180
supported by PyPlot. (Obviously, you must have installed one of these
@@ -242,7 +242,9 @@ surf(rand(30,40))
242242
to plot a random 30×40 surface mesh.
243243

244244
You can also explicitly create a subplot with 3d axes via, for
245-
example, `subplot(111, projection="3d")`, exactly as in Matplotlib.
245+
example, `subplot(111, projection="3d")`, exactly as in Matplotlib,
246+
but you must first call the `using3D()` function to ensure that
247+
mplot3d is loaded (this happens automatically for `plot3D` etc.).
246248
The `Axes3D` constructor and the
247249
[art3D](http://matplotlib.org/mpl_toolkits/mplot3d/api.html#art3d)
248250
module are also exported.

src/plot3d.jl

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,21 @@ keys(m::LazyPyModule) = keys(PyObject(m))
2222
const axes3D = LazyPyModule("mpl_toolkits.mplot3d.axes3d")
2323
const art3D = LazyPyModule("mpl_toolkits.mplot3d.art3d")
2424

25+
"""
26+
using3D()
27+
28+
This function ensures that the `mplot3d` module is loaded for 3d
29+
plotting. This occurs automatically if you call any of the
30+
3d plotting functions like `plot3D` or `surf`, but it may be
31+
necessary to call this function manually if you are passing
32+
`projection="3d"` explicitly to axes or subplot objects.
33+
"""
34+
using3D() = (PyObject(axes3D); nothing)
35+
2536
###########################################################################
2637
# 3d plotting functions from mplot3d
2738

28-
export art3D, Axes3D, surf, mesh, bar3D, contour3D, contourf3D, plot3D, plot_surface, plot_trisurf, plot_wireframe, scatter3D, text2D, text3D, zlabel, zlim, zscale, zticks
39+
export art3D, Axes3D, using3D, surf, mesh, bar3D, contour3D, contourf3D, plot3D, plot_surface, plot_trisurf, plot_wireframe, scatter3D, text2D, text3D, zlabel, zlim, zscale, zticks
2940

3041
const mplot3d_funcs = (:bar3d, :contour3D, :contourf3D, :plot3D, :plot_surface,
3142
:plot_trisurf, :plot_wireframe, :scatter3D,
@@ -34,7 +45,7 @@ const mplot3d_funcs = (:bar3d, :contour3D, :contourf3D, :plot3D, :plot_surface,
3445
for f in mplot3d_funcs
3546
fs = string(f)
3647
@eval @doc LazyHelp(axes3D,"Axes3D", $fs) function $f(args...; kws...)
37-
PyObject(axes3D) # make sure mplot3d is loaded
48+
using3D() # make sure mplot3d is loaded
3849
ax = gca(projection="3d")
3950
pycall(ax[$fs], PyAny, args...; kws...)
4051
end
@@ -50,7 +61,7 @@ const zlabel_funcs = (:zlabel, :zlim, :zscale, :zticks)
5061
for f in zlabel_funcs
5162
fs = string("set_", f)
5263
@eval @doc LazyHelp(axes3D,"Axes3D", $fs) function $f(args...; kws...)
53-
PyObject(axes3D) # make sure mplot3d is loaded
64+
using3D() # make sure mplot3d is loaded
5465
ax = gca(projection="3d")
5566
pycall(ax[$fs], PyAny, args...; kws...)
5667
end

0 commit comments

Comments
 (0)