matplotlib - How to plot a stacked histogram with two arrays in python -


i trying create stacked histogram showing clump thickness malignant , benign tumors, malignant class colored red , benign class colored blue.

i got clump_thickness_array , benign_or_malignant_array. benign_or_malignant_array consists of 2s , 4s.

  1. if benign_or_malignant equals 2 benign(blue colored).
  2. if equals 4 malignant(red colored).

i can not figure out how color benign , malignant tumors. histogram showing other try achieve.

this code , histogram far:

fig, ax = plt.subplots(figsize=(12,8)) tmp = list() in range(2): indices = np.where(benign_or_malignant>=i ) tmp.append(clump_thickness[indices])  ax.hist(tmp,bins=10,stacked=true,color = ['b',"r"],alpha=0.73) 

enter image description here

to obtain stacked histogram using lists of different length each group, need assemble list of lists. doing tmp variable. however, think using wrong indexes in loop. above, state want label data according variable benign_or_malignant. want test if 2 or 4. if want these 2 possibilities, rewrite this:

for in [2,4]:    indices = np.where(benign_or_malignant==i )    tmp.append(clump_thickness[indices]) 

Comments

Popular posts from this blog

Java Entity Manager - JSON reader was expecting a value but found 'db' -

many to many - Django Rest Framework ManyToMany filter multiple values -

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -