Jan-29-2021, 02:25 PM
Hi all
I try to visualise the content of a storage hall in a 3d scatter plot. In fact, I try to do a 5d:
X, Y, Z are the position of the item
TYPE is the marker used to visualise the type of the storage good
VALUE is the color of the marker, a property of the storage good
TYPE and VALUE are binned values from previous processing. Works fine.
But the color mapping doesn't work. In my sample code below, you should only see ONE red marker.
Can any one help me with the color mapping, including labelling the map? I don't know what I am doing in this field...
And the legend should indicate the type. OK, its colors are also a bit funnny, but ok...
I know it's a lot to read & think, but I'd appreciate your help a lot.
Thanks, Stephan
I try to visualise the content of a storage hall in a 3d scatter plot. In fact, I try to do a 5d:
X, Y, Z are the position of the item
TYPE is the marker used to visualise the type of the storage good
VALUE is the color of the marker, a property of the storage good
TYPE and VALUE are binned values from previous processing. Works fine.
But the color mapping doesn't work. In my sample code below, you should only see ONE red marker.
Can any one help me with the color mapping, including labelling the map? I don't know what I am doing in this field...
And the legend should indicate the type. OK, its colors are also a bit funnny, but ok...
I know it's a lot to read & think, but I'd appreciate your help a lot.
Thanks, Stephan
%matplotlib qt import pandas as pd import numpy as np import matplotlib.pyplot as plt import matplotlib.colors from mpl_toolkits.mplot3d import Axes3D data_d ={ "TYPE":[0,0,0,0,1,1,1,1,2,2,2,2], "X":[0,1,2,3,0,1,2,3,0,1,2,3], "Y":[1,1,1,1,2,2,2,2,3,3,3,3], "Z":[1,1,1,1,1,1,1,1,1,1,1,1], "VALUE":[0,1,2,0,0,1,2,3,1,1,2,0]} data = pd.DataFrame(data_d) marker_size = 100 markers = {0:'o', 1:'D', 2:'s'} colors = ["lightgrey", "green", "blue", "red"] color_map = matplotlib.colors.LinearSegmentedColormap.from_list("", ["lightgrey","green","blue","red"],4) bin_labels = ["Value 0","Value 1","Value 2","Value 3"] descriptions = {0:"Type 0", 1:"Type 1", 2:"Type 2"} fig = plt.figure() ax = fig.add_subplot(1,1,1, projection='3d') ax.title.set_text('Test 3d') pnt3d=0 for m in markers: print("Marker: ",m) data_part = data[data['TYPE'] == m] pnt3d=ax.scatter(data_part['X'], data_part['Y'], data_part['Z'], marker=markers[m], c=data_part['VALUE'], cmap = color_map, s=marker_size, depthshade=False, label=descriptions[m]) ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') cbar = plt.colorbar(pnt3d) cbar.ax.set_yticklabels(bin_labels) cbar.set_label("Color Labels") ax.legend( loc='best') plt.show()