Skip to content

fix for 3d subplots #545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

fix for 3d subplots #545

wants to merge 1 commit into from

Conversation

PaulSoderlind
Copy link

The current implementation has the problem that it overwrites subplots (see #532).

One of the problems with finding a good solution is (I believe) that the projection of an existing subplot cannot be easily changed. With this PR, the following works well

x = collect(-10:10)
y = collect(-11:11)
z = x.^2 .+ y'.^2

using PyPlot

figure()
subplot(221,projection="3d")
  surf(x, y, z')
  zlim(0,250)
  title("A")
subplot(222,projection="3d")
  surf(x, y, -z')
  zlim(-250,0)
  title("B")

figure()
  #ax = PyPlot.axes(projection="3d")     #works w/wo this
  surf(x, y, z')
  zlim(0,250)
  title("A")

if PyPlot.version <= v"3.4"
ax = gca(projection="3d")
else
ax = gca()._subplotspec.get_geometry() == (1,1,0,0) ? plt."subplot"(projection="3d") : gca()
Copy link
Member

@stevengj stevengj Apr 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ax = gca()._subplotspec.get_geometry() == (1,1,0,0) ? plt."subplot"(projection="3d") : gca()
ax = gca()."get_subplotspec"()."get_geometry"() == (1,1,0,0) ? plt."subplot"(projection="3d") : gca()

seems to be the documented way to get the current subplotspec. (Also I tend to use quotes to suppress the attempt at conversion (which fails, but takes up time).)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we just do

plt."subplot"(gca()."get_subplotspec"(), projection="3d")

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants