FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[Bug]: surface_plot cannot generate image even the axis · Issue #24725 · matplotlib/matplotlib · GitHub

Repository navigation

[Bug]: surface_plot cannot generate image even the axis #24725

Closed

Description

Bug summary

When I used surface_plot function with matplotlib version 3.6.2 on MacOS to draw a 3D image, nothing appears even the axis.
When I tried to degrade matplotlib to 3.5 and run the same code, it works.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from scipy.stats import multivariate_normal
def Gaussian_Distribution(N=2, M=1000, m=0, sigma=1):
    mean = np.zeros(N) + m
    cov = np.eye(N) * sigma

    data = np.random.multivariate_normal(mean, cov, M)
    Gaussian = multivariate_normal(mean=mean, cov=cov)
    
    return data, Gaussian

M = 100
data, Gaussian = Gaussian_Distribution(N=2, M=M, sigma=0.1)
X, Y = np.meshgrid(np.linspace(-1,1,M), np.linspace(-1,1,M))
d = np.dstack([X,Y])
Z = Gaussian.pdf(d).reshape(M,M)


fig = plt.figure(figsize=(6,4))
ax = Axes3D(fig)
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='seismic', alpha=0.8)

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.savefig('123.png')
plt.show()

Actual outcome

Expected outcome

Additional information

No response

Operating system

No response

Matplotlib Version

3.6.2

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

Activity

  1. greglucas commented on Dec 14, 2022

    Contributor

    That is not a recommended way to add a 3D axes to a figure since version 1.0.
    https://matplotlib.org/stable/tutorials/toolkits/mplot3d.html#sphx-glr-tutorials-toolkits-mplot3d-py

    Change ax = Axes3D(fig) to ax = fig.add_subplot(projection='3d')

  2. rcomer commented on Dec 14, 2022

    Member

    Since #24715 is documenting that Axes should not be instantiate directly, I guess that closes this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL