Python Forum
Matplotlib Color map problems
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Matplotlib Color map problems
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
%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],
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')
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])


cbar = plt.colorbar(pnt3d)
cbar.set_label("Color Labels")

ax.legend( loc='best')

Possibly Related Threads…
Thread Author Replies Views Last Post
  Oct2py and Matplotlib installation problems Leloup 2 1,798 Nov-23-2018, 03:32 PM
Last Post: Leloup

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020