Hi everyone,
I have successfully plotted a set of 372 (x,y,z ) scattered values in 7 series. Each point is a circle colored according to a color based on a simple lookup table.
Lookup table for color
col_lut = dict(Bistris7p2 = “burlywood”, Cit7p2 = “c”,APhosph8p0 = “m”, Acetate5p5 = “k”,Borate8p5 = “y”,Mes6p7 = “c”,Hep8p2 = “g”,ATris9p0 = “r”)
I was wondering how can I have a legend for this color code positioned somewhere alongside or within the interactive 3D figure.
The legend text would be the col_lut keys and the colored values would be a box or circle filled with color alongside. I am sorry I couldnt find an appropriate example to help with the legend creation and am asking to be spoon fed.
Do I use a matplotlib widget or some other utility to programmatically do this.
Thanks for your help
Hari
My code is as follows:
#!/usr/bin/python
import csv file with pH ,salt_conc , temp and do a 3d plot
import csv
from mpl_toolkits.mplot3d.axes3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.colors import ListedColormap
ph = []
salt_conc = []
tm = []
buffcomp = []
Get the raw data
f = open(“stability_buffer_matrix_lookup_table_temp.csv”)
csvfile = csv.reader(f)
#color lookup table
col_lut = dict(Bistris7p2 = “burlywood”, Cit7p2 = “c”,APhosph8p0 = “m”, Acetate5p5 = “k”,Borate8p5 = “y”,Mes6p7 = “c”,Hep8p2 = “g”,ATris9p0 = “r”)
for i in csvfile:
weed out incomplete data points
if "" not in i:
ph.append(float(i[4]))
salt_conc.append(float(i[5]))
tm.append(float(i[-1]))
#gets a color from the lookup table based on the buffer component entry
buffcomp.append(col_lut[i[3]])
print set(buffcomp) , col_lut
fig = plt.figure(figsize=plt.figaspect(0.5))
ax = fig.add_subplot(1, 1, 1, projection=‘3d’)
surf = ax.scatter(ph,salt_conc,tm, c=buffcomp)
ax.set_xlabel(‘pH’)
ax.set_ylabel(‘Salt Conc’)
ax.set_zlabel(‘Tm’)
#Tried this does not show up
#colmap = ListedColormap(col_lut.values())
#colmap.Bounds = range(len(col_lut.keys()) +1 )
plt.show()