Без данных, которые вы наберете sh, трудно ответить на ваш вопрос. Однако обычно для построения функции IR ^ 2, например z = (x, y), большинство инструментов построения графиков требуют, чтобы x, y, z были двумерными массивами или матрицами. Ваши данные уже подготовлены для этого, так как значения внутри столбцов повторяются. Так что вам просто нужно преобразовать столбцы данных в 2D-массивы. Обновите time
, velocity
, cxx
, time_points
и velocity_points
своими данными и проверьте, работает ли для вас следующий код.
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
# some data
time = [-1.0, -0.999, -0.998, 0.998, 0.999, 1.0, -1.0, -0.999, -0.998, 0.998, 0.999, 1.0]
velocity = [-10000, -10000, -10000, -10000, -10000, -10000, -5000, -5000, -5000, -5000, -5000, -5000]
cxx = [0.000, 0.010, 0.011, 0.011, 0.010, 0.000, 0.000, 0.050, 0.055, 0.055, 0.050, 0.000]
time_points = 6 # -1.0, -0.999, -0.998, 0.998, 0.999, 1.0
velocity_points = 2 # -10000, -5000
# reshape data into matrices
x = np.reshape(time, (velocity_points, time_points))
y = np.reshape(velocity, (velocity_points, time_points))
z = np.reshape(cxx, (velocity_points, time_points))
# 1.1. plot a 3d graph (surface plot)
fig = plt.figure(1)
ax = fig.gca(projection='3d')
ax.plot_surface(x, y, z)
ax.set_xlabel('Time')
ax.set_ylabel('Velocity')
ax.set_zlabel('Cxx')
# 1.2. plot a 3d graph (surface plot) with a colormap and colorbar
fig = plt.figure(2)
ax = fig.gca(projection='3d')
surf = ax.plot_surface(x, y, z, cmap='jet')
plt.colorbar(surf)
ax.set_xlabel('Time')
ax.set_ylabel('Velocity')
ax.set_zlabel('Cxx')
# 2. heatmap with colorbar
fig = plt.figure(3)
ax = fig.gca()
plt.contourf(x, y, z, cmap='jet')
cbar = plt.colorbar()
ax.set_xlabel('Time')
ax.set_ylabel('Velocity')
cbar.set_label('Cxx')
# 3. direct view of Cxx values in a grid
fig = plt.figure(4)
ax = fig.gca()
plt.imshow(z, cmap='jet', interpolation='nearest')
cbar = plt.colorbar()
ax.set_xlabel('Time Index')
ax.set_ylabel('Velocity Index')
cbar.set_label('Cxx')
# show
plt.show()