0

I am trying to do CFD using python and I am following this Jupyter notebook . I am currently in cell 1 where they plot the initial conditions but the the repo seems to be too old and that code wasn't working. I tried following this post in Stackoverflow but I am still not getting any plot and the output is <Figure size 1100x700 with 0 Axes> that's it.

Matplotlib version - 3.7.1

Here's my code -

import numpy as np
import sympy as sy
import matplotlib.pyplot as plt
%matplotlib inline

from mpl_toolkits.mplot3d import Axes3D

# variable declarations
n_x = 91
n_y = 81
nt = 100
c = 1
dx = 2/(n_x - 1)
dy = 2/(n_y - 1)
sigma = 0.2
dt = sigma*dx

x = np.linspace(0,2,n_x)
y = np.linspace(0,2,n_y)

u = np.ones((n_y,n_x))
un = np.ones((n_y,n_x))

## Assigning Initial Conditions

u[int(0.5/dx) : int(1/dx + 1), int(0.5/dy) : int(1/dy + 1)] = 2

###PLotting initial condition

fig = plt.figure(figsize=(11,7), dpi=100)
ax = Axes3D(fig)
#ax = fig.gca(projection = '3d')
X,Y = np.meshgrid(x,y)
#surf = ax.plot_surface(X,Y,u[:],cmap=cmaps.viridis)
cset = ax.contour(X,Y,u[:],extend3d='True')
ax.clabel(cset,fontsize = 9, inline = 1)
plt.show()

Where am I going wrong?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
  • replace `ax = Axes3D(fig)` by `ax = fig.add_subplot(projection='3d')`, see note in the [docs](https://matplotlib.org/stable/api/toolkits/mplot3d/axes3d.html#mpl_toolkits.mplot3d.axes3d.Axes3D): "As a user, you do not instantiate Axes directly, but use Axes creation methods instead; e.g. from pyplot or Figure: subplots, subplot_mosaic or Figure.add_axes." – Stef Jun 01 '23 at 06:29

0 Answers0