2

I have a code to graph mi function f(x,y)=(x^4 + y^4). I already imported all the necessary libraries, but when i run it, the "MatplotlibDeprecationWarning: Axes3D(fig) adding itself to the figure is deprecated since 3.4. Pass the keyword argument auto_add_to_figure=False and use fig.add_axes(ax) to suppress this warning. The default value of auto_add_to_figure will change to False in mpl3.5 and True values will no longer work in 3.6. This is consistent with other Axes classes." error shows. This is my code: `

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
 
figura = plt.figure() 
ejes = Axes3D(figura) 
plt.show() 

def f(x,y):
    return ((x**4)+(y**4)) 

x = np.linspace(-2,2,40) 
y = np.linspace(-2,2,40)

x,y = np.meshgrid(x,y)

z= f(x,y) 

ejes.plot_wireframe(x,y,z)

`

1 Answers1

1

On my environment it actually works. Anyway you can obtain the same plot using the "3d" projection of pyplot:

import numpy as np
import matplotlib.pyplot as plt
 

figura = plt.figure(figsize=(7,7))
ejes = plt.subplot(111, projection="3d")

def f(x,y):
    return ((x**4)+(y**4)) 

x = np.linspace(-2,2,40) 
y = np.linspace(-2,2,40)

x,y = np.meshgrid(x,y)

z= f(x,y) 

ejes.plot_wireframe(x,y,z)
plt.show()
  • how does the "3d" projection of pyplot works?? It actually worked on my environment but can you make a brief explanation on how it works?? – Luis Barajas Mar 10 '22 at 23:06
  • It works like `Axes3D`: https://stackoverflow.com/questions/53103168/add-subplot111-projection-3d-vs-axes3dfig. Anyway to avoid your warning you can just add to `Axes3D` the parameter `auto_add_to_figure=False` – Salvatore Daniele Bianco Mar 11 '22 at 08:39