python - Labeling stacked histogram bins with frequency of only one of the stacks -


i've made histogram of data. represents bunch of stars, of have been observed, others of have not. white space represents ones not observed. make above bins there white space, label amount of white counts in bins, ignore green , orange. if above bins complex, below them fine well. wherever simplest. here's plot , code:

plot

import numpy np import matplotlib.pyplot plt import matplotlib.patches mpatches matplotlib import font_manager  # hfont = {'fontname':'computer modern'}  filename = ("master.kkids.obslist")  datadata = np.loadtxt(filename,skiprows=14,dtype=str)  x = datadata[:,7] y = datadata[:,8] u = datadata[:,18] v = datadata[:,19] z = datadata[:,20]  yesgem = (v == "y") & (u == "gemn") yesdct = (v == "y") & (u == "dct") no = (v == "n")  x1 = x.astype(float) y1 = y.astype(float) x2 = x1*24/360  colors = ['green', 'orange', 'white'] labels = ['gemn','dct','not observed']  plt.xlim(0,24)  plt.hist((x2[yesgem],x2[yesdct],x2[no]), 24, label=labels, color=colors, histtype='bar', stacked=true)  plt.legend(fancybox=true,shadow=true)  plt.ylabel('frequency') plt.xlabel('right ascension (h)')  plt.savefig('kkids.hist.png') 

the general pattern can loop on x axis, each stack check if there 'not observed', if so, fetch values of gemn + dct + (not observed / 2) observation, use these 2 values x , y plot desired text (i.e value of not observed) using plt.text(x, y, text).

so if y understand correctly dataset, guess should job :

# returned arrays plt.hist, contain stacked frequencies phist = plt.hist((x2[yesgem],x2[yesdct],x2[no]), 24, label=labels,                  color=colors, histtype='bar', stacked=true) plt.legend(fancybox=true,shadow=true) plt.ylabel('frequency') plt.xlabel('right ascension (h)') # reshape frequencies values : stack_plots = \     np.concatenate(phist[0]).reshape(len(labels), len(phist[0][0])).t  nb_x, stack in enumerate(stack_plots):     # 'stack' array frequency of [gem, dct + gem, cdt + gem + no]     if stack[2] - stack[1] != 0: # if there not observed..         # compute coords text :         x_text = nb_x         y_text = stack[1] + (stack[2] - stack[1]) / 2         # , plot it:         plt.text(x_text, y_text, round(stack[2] - stack[1]), verticalalignment='center') 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -