skip to Main Content

I want to draw a 3D picture with these data using matplotlib and Axes3D

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

data = np.array([[4244.95, 4151.69, 2157.41, 829.769, 426.253, 215.655],
                 [8263.14, 4282.98, 2024.68, 1014.6, 504.515, 250.906],
                 [8658.01, 4339.53, 2173.56, 1087.65, 544.069, 544.073]])

x = np.array([1, 2, 4, 8, 16, 32])
y = np.array([2, 4, 8])
x, y = np.meshgrid(x, y)
z = data

fig = plt.figure()
ax = Axes3D(fig)

ax.plot_surface(x, y, z, rstride=1, cstride=1, cmap='rainbow')

ax.set_xlabel('Stride')
ax.set_ylabel('Bitwidth')
ax.set_zlabel('Performance')

plt.show()

In my computer, it gives a blank picture. But I run this code in other two computers, one is correct, the other one is blank.

matplotlib: 3.7.1

numpy: 1.24.2

I have tried in windows11 and wsl ubuntu-20.04, but still the blank pictures.

2

Answers


  1. replace this line

    ax = Axes3D(fig)
    

    with

    ax = fig.add_subplot(projection='3d')
    

    you do this in order to alert Matplotlib that we’re using 3d data.

    Login or Signup to reply.
  2. Your code runs fine on my machine, maybe try a different backend for matplotlib.

    import matplotlib
    matplotlib.use('Agg')
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search