I have been searching the internet for the past couple of days and I have not seen any solution. I will be grateful if someone can please have a look.
I am trying to plot a 4D plot to show wind direction variation at a given longitude, latitude, and altitude.
I see a jump in my graph when the object moves from one altitude to the other. Is it possible to connect the points with a line? to indicate that the is a movement.
The sample code is shown below:
import numpy as np
from matplotlib import pyplot as plt
lon = np.array([278.6695, 278.67,278.672265 ])
lat = np.array([48.476151, 48.472578621119, 48.45994295 ])
Z = np.array([20000, 26502.51477,26501.65171])
distance = np.array([72.63856248, 70, 60 ])
fig = plt.figure(6)
ax = fig.add_subplot(111, projection='3d')
img = ax.scatter(lon, lat, Z, c=distance, cmap='inferno', alpha=1)
fig.colorbar(img)
ax.set_xlabel('longitude [Deg]')
ax.set_ylabel('latitude [Deg]')
ax.set_zlabel('Altitude [Km]')
plt.show()
My result when I plot my whole data

Secondly, I would like to show the distance using just one colour (i.e. Black ) instead of using multiple colours. My end goal is to have a plot like this


This answer shows how to create the final plot that you asked for. Both requests (single color and connected line) are very possible. A Google search of your desired plot image shows that it was originally an
animation, which is something else that I have included.Answer
Use
ax.plot(...)instead ofax.scatter(...)in order to connect the points with a line. Then you can add a few other features to make the output look more like your end goal.Example Output
Here is a figure showing your end goal. The code to reproduce the figure is added below.
It is also possible to create an animation of the plot over time. Note that the color of the lines changes as the distance from the start position increases. This feature is easily disabled.
Code
This is some setup code to be used for both static and animated figures.
This is for the static version of the figure.
This is the code to create an animated version of the plot over time.
Edit
In order to fix the animation portion of the code to be compatible with Matplotlib 3.5.1, you must change the following section of code in the
animate(...)function. Replace the following:With:
All this does is change the input for the
set_3d_properties(...)to list format, which is the new standard in Matplotlib 3.5.1. See this open issue for a description of the problem.Does this help?