I'm trying to draw a 3D line plot with the toolkits mplot3D of matplotlib I have 4 arrays
I've draw my plot with this:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig1 = plt.figure()
ax = fig1.gca(projection='3d')
ax.plot(tab_C[0], tab_C[1], tab_C[2])
plt.show()
It works but now I want this plot have rainbow coloring based on the time-value. I've searched the web page of matplotlib but there's nothing. Any suggestion on this problem?
A three-dimensional axes can be created by passing the keyword projection='3d' to any of the normal axes creation routines. We can now plot a variety of three-dimensional plot types. The most basic three-dimensional plot is a 3D line plot created from sets of (x, y, z) triples. This can be created using the ax.
Matplotlib was introduced keeping in mind, only two-dimensional plotting. But at the time when the release of 1.0 occurred, the 3d utilities were developed upon the 2d and thus, we have 3d implementation of data available today! The 3d plots are enabled by importing the mplot3d toolkit.
The 3D plotting in Matplotlib can be done by enabling the utility toolkit. The utility toolkit can be enabled by importing the mplot3d library, which comes with your standard Matplotlib installation via pip.
Get the hue colormap, defining a palette. Plot x, y and z data points using scatter () method. Place a legend on the plot. To display the figure, use show () method.
Contour plot is a way of showing a 3D graph by plotting constant z-slices. Filled contour fills the areas that were shown by the line in contour plots. The first step is to import all the necessary packages for plotting the above plot. Apart from matplotlib.pyplot and NumPy, we are importing another package which is mpl_toolkits.mplot3d.
One way to represent color is using CIELAB. In CIELAB, color space is represented by lightness, L ∗; red-green, a ∗; and yellow-blue, b ∗. The lightness parameter L ∗ can then be used to learn more about how the matplotlib colormaps will be perceived by viewers.
You can do it in pure matploblib fashion as Bill shows, but it is more intuitive with Mayavi. Here is a nice example from their documentation:
from mayavi import mlab
n_mer, n_long = 6, 11
dphi = np.pi / 1000.0
phi = np.arange(0.0, 2 * pi + 0.5 * dphi, dphi)
mu = phi * n_mer
x = np.cos(mu) * (1 + np.cos(n_long * mu / n_mer) * 0.5)
y = np.sin(mu) * (1 + np.cos(n_long * mu / n_mer) * 0.5)
z = np.sin(n_long * mu / n_mer) * 0.5
t = np.sin(mu)
mlab.plot3d(x, y, z, t, tube_radius=0.025, colormap='Spectral')
It is just the argument colormap
that determines the colormap, and x
, y
, z
, t
can be replaced by the particular array that you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With