'How to do create 3D surface plots with really large data in Python?
3D Surface Plotting in Python With Large Files
I am currently trying to do 3D surface plotting in Python, and have run into issues due to having a large dataset. I've tried using mpl.toolkits.mplot3d and the plot_surface function. I have been running into memory errors due to the data that I am using having 446082 data points. Here is a sample of the code I am using:
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import matplotlib.pyplot as plt
import numpy as np
%matplotlib tk
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
X, Y, Z= np.meshgrid(x, y, z)
my_col = cm.jet(var/np.amax(var))
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors = my_col,
linewidth=0, antialiased=False)
ax.set_zlim(-1.01, 1.01)
fig.colorbar(surf, ax=ax, shrink=0.5, aspect=5)
plt.show()
The variables x, y, z, and var are all arrays of type float64 with a length of 446082. My goal here is to plot the 3D figure that x, y, and z produce. I want the color plotted on the surface to change with respect to variable var, which is another set of data of the same size. The software Paraview does this, and it is basically what I am trying to recreate.
In the example I provided, the memory errors come from np.meshgrid(), where my large dataset breaks the code. I am now stuck as to what to do about this, since .plot_surface only takes in 2D arguments for x, y, z. Are there workarounds for this in matplotlib/mplot3d ? Should I try to find another library altogether? Are there better options? Or is what I am trying to do just not a feasible? I have tried with plotly and mayavi, but neither really accomplished what I wanted to do or they took a really long time to produce anything. Any help/guidance would be appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
