I know that the question is very old, but I would like to introduce this alternative, where instead of using the "scatter plot" we have a three-dimensional surface diagram, where the colors are based on the 4th dimension. Personally, I don’t see the spatial relationship in the case of a “scatter plot,” and therefore using a three-dimensional surface helps me understand the plot more easily.
The basic idea is similar to the accepted answer, but we have a three-dimensional surface graph that allows us to visually better see the distance between points. The following code is mainly based on the answer asked to this question .
import numpy as np from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import matplotlib.tri as mtri

Another solution for the case when we absolutely want to have the initial values of the 4th dimension for each point is simply to use a “scatter plot” in combination with a three-dimensional surface diagram, which simply links them to help you see the distances between them.
name_color_map_surface = 'Greens';

Finally, it is also possible to use "plot_surface", where we define the color that will be used for each face. In this case, when we have 1 vector of values per dimension, the problem is that we have to interpolate the values to get 2D meshes. In case of interpolation of the 4th dimension, it will be determined only in accordance with XY and Z will not be taken into account. As a result, colors represent C (x, y) instead of C (x, y, z). The following code is mainly based on the following answers: plot_surface with a one-dimensional vector for each dimension ; plot_surface with the selected color for each surface . Please note that, compared to previous solutions, the calculation is rather complicated, and the display may take some time.
import matplotlib from scipy.interpolate import griddata

source share