PyPlot.jl icon indicating copy to clipboard operation
PyPlot.jl copied to clipboard

Plot3D does not used current subplot

Open ahwillia opened this issue 9 years ago • 6 comments
trafficstars

Not sure if this is a known issue, but the following code gives me this not so nice output. (I'm currently checked out on master.)

using PyPlot
figure()
subplot(2,2,1)
plot(randn(10))
subplot(2,2,2)
plot3D(randn(10),randn(10),randn(10))

image

ahwillia avatar Jun 24 '16 14:06 ahwillia

All we do is to call gca(projection="3d") before the 3d plot, in the code here.

Maybe it is a Matplotlib limitation that you have to specify that you want 3d when you first create the subplots? For example, this seems to work:

fig = figure()
ax = fig[:add_subplot](222, projection="3d")
plot3D(randn(10),randn(10),randn(10))
subplot(2,2,1)
plot(randn(10))

stevengj avatar Jun 27 '16 19:06 stevengj

Thanks - I was hoping for a more automatic solution, but I think you may be right that this is a limitation of matplotlib. On Jun 27, 2016 12:08 PM, "Steven G. Johnson" [email protected] wrote:

All we do is to call gca(projection="3d") before the 3d plot, in the code here https://github.com/stevengj/PyPlot.jl/blob/27f62251e62cea431a955bafc4444472f4e96fe5/src/PyPlot.jl#L439-L445 .

Maybe it is a Matplotlib limitation that you have to specify that you want 3d when you create the subplots? For example, this seems to work:

fig = figure() ax = fig[:add_subplot](222, projection="3d")plot3D(randn(10),randn(10),randn(10))subplot(2,2,1)plot(randn(10))

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/stevengj/PyPlot.jl/issues/226#issuecomment-228844219, or mute the thread https://github.com/notifications/unsubscribe/AAm20VjifaL3bRQjW85vQ_INfCank9SYks5qQB-VgaJpZM4I9z9c .

ahwillia avatar Jun 27 '16 19:06 ahwillia

Hi, I tried the suggestion by @stevengj , but when I execute: fig = figure(); ax = fig[:add_subplot](222, projection="3d")

I get the following error: ERROR: PyError (ccall(@pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, arg, kw)) <class 'Val ueError'> ValueError("Unknown projection '3d'",) File "C:\Users\Rahul\Anaconda3\lib\site-packages\matplotlib\figure.py", line 1221, in add_subplot self, *args, **kwargs) File "C:\Users\Rahul\Anaconda3\lib\site-packages\matplotlib\projections\__init__.py", line 91, in process_projection_requirements projection_class = get_projection_class(projection) File "C:\Users\Rahul\Anaconda3\lib\site-packages\matplotlib\projections\__init__.py", line 65, in get_projection_class raise ValueError("Unknown projection '%s'" % projection)

However, when I use: ax = fig[:add_subplot](222) it generate 2d subplot correctly.

I'm using Julia:

versioninfo() Julia Version 0.6.3 Commit d55cadc350* (2018-05-28 20:20 UTC) Platform Info: OS: Windows (x86_64-w64-mingw32) CPU: Intel(R) Core(TM) i7-7820HK CPU @ 2.90GHz WORD_SIZE: 64 BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell) LAPACK: libopenblas64_ LIBM: libopenlibm LLVM: libLLVM-3.9.1 (ORCJIT, broadwell)

PyPlot.version v"2.2.2"

What could be workaround for this problem? In fact I'm trying to set the rotation angle of 3D plot, something equivalent to the following Python code:

import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = fig.gca(projection="3d") ax.view_init(azim=30)

How can I achieve in Julia? Thanks for your suggestions!

mouryarahul avatar Jul 25 '18 11:07 mouryarahul

See https://github.com/JuliaPy/PyPlot.jl#3d-plotting … you nowadays need to call using3D() before doing anything, e.g. this works:

using PyPlot
using3D()
subplot(2,2,1)
plot(randn(10))
subplot(2,2,2, projection="3d")
plot3D(randn(10),randn(10),randn(10))

stevengj avatar Jul 25 '18 16:07 stevengj

Thanks! @stevengj It works fine on Linux machine:

versioninfo() Julia Version 0.6.3 Commit d55cadc (2018-05-28 20:20 UTC) Platform Info: OS: Linux (x86_64-linux-gnu) CPU: Intel(R) Core(TM) i7-7820HK CPU @ 2.90GHz WORD_SIZE: 64 BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell) LAPACK: libopenblas64_ LIBM: libopenlibm LLVM: libLLVM-3.9.1 (ORCJIT, broadwell)

PyPlot.version v"2.2.2"

Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) [GCC 7.2.0] on linux

However, on Windows machine with same versions, I get error:

using3D is not defined!

mouryarahul avatar Aug 01 '18 15:08 mouryarahul

Probably your Windows machine has an older version of the PyPlot package. Do Pkg.update() to update your packages, or run Pkg.status() to find out whether you've pinned the package version.

stevengj avatar Aug 01 '18 16:08 stevengj