def generate_chart(X, centroids, labels, n_cluster): chart = scatterChart(name='scatterChart', height=800, width=1400) centxlist = [] centylist = [] for i in range(n_cluster): newxlist = [] newylist = [] centylist.append(newxlist) centxlist.append(newylist) for i in range(len(X)): centxlist[labels[i]].append(X[i][0]) centylist[labels[i]].append(X[i][1]) kwargs1 = {'shape': 'circle', 'size': '1'} kwargs2 = {'shape': 'cross', 'size': '5'} for i in range(n_cluster): chart.add_serie(name="Centroid_" + str(i), y=centylist[i], x=centxlist[i], **kwargs1) chart.add_serie(name="Centroids", y=centroids[:, 1], x=centroids[:, 0], **kwargs2) chart.buildhtml() return chart.htmlcontent
def scatter_chart(xs, ys, labels): chart = nvd3.scatterChart(name="", height=350, x_is_date=False) extra_serie = {"tooltip": {"y_start": "", "y_end": "value"}} for x, y, label in zip(xs, ys, labels): chart.add_serie(name=label, y=y, x=x, extra=extra_serie) chart.buildcontent() # assuming name is hardcoded to "" return js_extract(chart.htmlcontent).replace("# svg", "#results_graph")
def scatter_plot(): content = read_data('/var/www/html/assignment5/static/dataset_chart1.csv') station, ydata = validate_data(content) kwargs1 = {'shape': 'circle', 'size': '1','margin_top': 100} chart = scatterChart(name='scatterChart', height=1800, width=1800, margin_bottom=200, margin_top=40, margin_left=60, margin_right=10) xdata = list(range(1,13)) for it in range(0,len(station)-1): chart.add_serie(y=ydata[it],x=xdata,name=station[it],**kwargs1) chart.buildhtml() return chart.htmlcontent
def calculateCorrelation(self,getTickerData): output_file = open('calculateCorrelation.html', 'w') type = "scatterChart" chart = scatterChart(name=type, x_is_date=False, height=450, width=1300) extra_serie = {"tooltip": {"y_start": "", "y_end": " call"}} kwargs2 = {'shape': 'cross', 'size': '10'} dfAAPL = getTickerData('AAPL')['Open'] dfGOOG = getTickerData('GOOG')['Open'] chart.add_serie(y=dfGOOG, x=dfAAPL, name='Correlation', extra=extra_serie, **kwargs2) chart.buildhtml() output_file.write(chart.htmlcontent) output_file.close()
def get_html(selected_stock): from nvd3 import lineWithFocusChart, scatterChart, lineChart trade_objs = TradeModel.objects.all() selected_trades = [ trade_obj.__dict__ for trade_obj in trade_objs if trade_obj.tradingsymbol == selected_stock ] # chart = lineWithFocusChart(name='lineWithFocusChart', x_is_date=True, x_axis_format="%d %b %Y", height=400, width=1000) chart = scatterChart(name='scatterChart', x_is_date=True, x_axis_format="%d %b %Y", height=400, width=1000) xdata = [1491004800000] ydata = [None] ydata1 = [None] for trade in selected_trades: xdata.append(int(trade['order_execution_time'].strftime('%s') + "000")) if trade['trade_type'] == "buy": ydata.append(trade['price']) ydata1.append(None) else: ydata.append(None) ydata1.append(trade['price']) xdata.append(int(round(time.time() * 1000))) ydata.append(None) ydata1.append(None) extra_serie = { "tooltip": { "y_start": "", "y_end": " balls" }, "date_format": "%d %b %Y" } kwargs = {'size': '50'} chart.add_serie(name="BUY", y=ydata, x=xdata, extra=extra_serie, **kwargs) chart.add_serie(name="SELL", y=ydata1, x=xdata, extra=extra_serie, **kwargs) chart.buildhtml() return chart.htmlcontent
def test_scatterChart(self): """Test Scatter Chart""" type = "scatterChart" chart = scatterChart(name=type, date=True, height=350) nb_element = 100 xdata = [i + random.randint(1, 10) for i in range(nb_element)] ydata = [i * random.randint(1, 10) for i in range(nb_element)] ydata2 = [x * 2 for x in ydata] ydata3 = [x * 5 for x in ydata] kwargs1 = {'shape': 'circle', 'size': '1'} kwargs2 = {'shape': 'cross', 'size': '10'} kwargs3 = {'shape': 'triangle-up', 'size': '100'} chart.add_serie(y=ydata, x=xdata, **kwargs1) chart.add_serie(y=ydata2, x=xdata, **kwargs2) chart.add_serie(y=ydata3, x=xdata, **kwargs3) chart.buildhtml()
def test_scatterChart(self): """Test Scatter Chart""" type = "scatterChart" chart = scatterChart(name=type, date=True, height=350) nb_element = 100 xdata = [i + random.randint(1, 10) for i in range(nb_element)] ydata = [i * random.randint(1, 10) for i in range(nb_element)] ydata2 = list(map(lambda x: x * 2, ydata)) ydata3 = list(map(lambda x: x * 5, ydata)) kwargs1 = {'shape': 'circle'} kwargs2 = {'shape': 'cross'} kwargs3 = {'shape': 'triangle-up'} chart.add_serie(y=ydata, x=xdata, **kwargs1) chart.add_serie(y=ydata2, x=xdata, **kwargs2) chart.add_serie(y=ydata3, x=xdata, **kwargs3) chart.buildhtml()
def test_scatterChart(self): """Test Scatter Chart""" type = "scatterChart" chart = scatterChart(name=type, date=True, height=350) nb_element = 100 xdata = [i + random.randint(1, 10) for i in range(nb_element)] ydata = [i * random.randint(1, 10) for i in range(nb_element)] ydata2 = map(lambda x: x * 2, ydata) ydata3 = map(lambda x: x * 5, ydata) kwargs1 = {'shape': 'circle'} kwargs2 = {'shape': 'cross'} kwargs3 = {'shape': 'triangle-up'} chart.add_serie(y=ydata, x=xdata, **kwargs1) chart.add_serie(y=ydata2, x=xdata, **kwargs2) chart.add_serie(y=ydata3, x=xdata, **kwargs3) chart.buildhtml()
def hello(): input_data = list( csv.reader(open('dateCrimeOutput.txt', 'rb'), delimiter='\t')) chart = scatterChart(name='scatterChart', height=800, width=1800, margin_top=350) crimes = [] for row in input_data: crimes.append([row[0], row[1], int(row[2])]) crimes = sorted(crimes, key=lambda crimes: ([crimes[0], crimes[1]])) xdata = [] current_crime = None i = 0 for crime in crimes: if str(crime[0]) == current_crime: xdata.append(crime[1]) globals()['ydata%s' % i].append(crime[2]) else: current_crime = crime[0] i = i + 1 globals()['name%s' % i] = str(crime[0]) globals()['ydata%s' % i] = [] xdata.append(str(crime[1])) globals()['ydata%s' % i].append(crime[2]) kwargs1 = {'shape': 'circle', 'size': '20'} # kwargs2 = {'shape': 'cross', 'size': '4'} i = 1 while True: try: chart.add_serie(name=globals()['name%s' % i], y=globals()['ydata%s' % i], x=xdata, **kwargs1) i = i + 1 except: break chart.buildhtml() return chart.htmlcontent
def make_plot(xdata, ydata): output_file = open('../templates/roary/scatterChart.html', 'w') type = "scatterChart" chart = scatterChart(name=type, height=350, width=550, x_is_date=False) kwargs1 = {'shape': 'circle', 'size': '1'} extra_serie = {"tooltip": {"y_start": "", "y_end": " calls"}} chart.add_serie(name="songs", y=ydata, x=xdata, extra=extra_serie, **kwargs1) chart.buildhtml() chart.htmlcontent = chart.htmlcontent.replace('./bower', './static/js/bower') output_file.write(chart.htmlcontent) output_file.close()
def calculateCorrelation(self, getTickerData): output_file = open('calculateCorrelation.html', 'w') type = "scatterChart" chart = scatterChart(name=type, x_is_date=False, height=450, width=1300) extra_serie = {"tooltip": {"y_start": "", "y_end": " call"}} kwargs2 = {'shape': 'cross', 'size': '10'} dfAAPL = getTickerData('AAPL')['Open'] dfGOOG = getTickerData('GOOG')['Open'] chart.add_serie(y=dfGOOG, x=dfAAPL, name='Correlation', extra=extra_serie, **kwargs2) chart.buildhtml() output_file.write(chart.htmlcontent) output_file.close()
def generate_chart(X,centroids,labels,n_cluster): chart = scatterChart(name='scatterChart', height=800, width=1400) centxlist = [] centylist = [] for i in range(n_cluster): newxlist = [] newylist = [] centylist.append(newxlist) centxlist.append(newylist) for i in range(len(X)): centxlist[labels[i]].append(X[i][0]) centylist[labels[i]].append(X[i][1]) kwargs1 = {'shape': 'circle', 'size': '1'} kwargs2 = {'shape': 'cross', 'size': '5'} for i in range(n_cluster): chart.add_serie(name="Centroid_" + str(i), y=centylist[i], x=centxlist[i],**kwargs1) chart.add_serie(name="Centroids", y=centroids[:,1],x=centroids[:,0],**kwargs2) chart.buildhtml() return chart.htmlcontent
from nvd3 import scatterChart %load_ext rpy2.ipython from rpy2.robjects import pandas2ri pandas2ri.activate() from rpy2.robjects import r import pandas df_cars = pandas2ri.ri2py(r['mtcars']) wt = df_cars['wt'] mpg = df_cars['mpg'] kwargs = {'shape': 'circle', 'size': '1'} chart = scatterChart(name='Weight vs MPG', height=400, width=800, y_axis_scale_min='0', show_legend='False') chart.add_serie(name="Cars", x=wt, y=mpg, **kwargs) output_file = open('nvd3-2.html', 'w') chart.buildhtml() output_file.write(chart.htmlcontent) output_file.close()
ydata2 = map(lambda x: x * 2, ydata) tooltip_date = "%d %b %Y %H:%M:%S %p" extra_serie = {"tooltip": {"y_start": "There are ", "y_end": " calls"}, "date_format": tooltip_date} chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie) extra_serie = {"tooltip": {"y_start": "There are ", "y_end": " duration"}, "date_format": tooltip_date} chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie) chart.buildcontent() output_file.write(chart.htmlcontent) # --------------------------------------- type = "scatterChart" chart = scatterChart(name=type, height=350, width=800, x_is_date=False) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") nb_element = 50 xdata = [i + random.randint(1, 10) for i in range(nb_element)] ydata = [i * random.randint(1, 10) for i in range(nb_element)] ydata2 = [x * 2 for x in ydata] ydata3 = [x * 5 for x in ydata] kwargs1 = {'shape': 'circle', 'size': '1'} kwargs2 = {'shape': 'cross', 'size': '10'} kwargs3 = {'shape': 'triangle-up', 'size': '100'} extra_serie = {"tooltip": {"y_start": "", "y_end": " calls"}} chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie, **kwargs1) chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie, **kwargs2) chart.add_serie(name="serie 3", y=ydata3, x=xdata, extra=extra_serie, **kwargs3)
ydata2 = map(lambda x: x * 2, ydata) tooltip_date = "%d %b %Y %H:%M:%S %p" extra_serie = {"tooltip": {"y_start": "There are ", "y_end": " calls"}, "date_format": tooltip_date} chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie) extra_serie = {"tooltip": {"y_start": "There are ", "y_end": " duration"}, "date_format": tooltip_date} chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie) chart.buildcontent() output_file.write(chart.htmlcontent) #--------------------------------------- type = "scatterChart" chart = scatterChart(name=type, height=350, date=False, jquery_on_ready=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") nb_element = 50 xdata = [i + random.randint(1, 10) for i in range(nb_element)] ydata = [i * random.randint(1, 10) for i in range(nb_element)] ydata2 = [x * 2 for x in ydata] ydata3 = [x * 5 for x in ydata] kwargs1 = {'shape': 'circle', 'size': '1'} kwargs2 = {'shape': 'cross', 'size': '10'} kwargs3 = {'shape': 'triangle-up', 'size': '100'} extra_serie = {"tooltip": {"y_start": "", "y_end": " calls"}} chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie, **kwargs1) chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie, **kwargs2) chart.add_serie(name="serie 3", y=ydata3, x=xdata, extra=extra_serie, **kwargs3)
def grade_vs_nchapters(self, **kwargs): """ Scatter plot of final grade versus nchapters accessed. All points are jittered for clarity. Text labels are added to indicate subpopulations. Parameters ---------- NVD3 = False. If true, nvd3 interactive figure output. Output ------ Figures and respective formats. Returns ------- None """ NVD3 = kwargs.get('NVD3', False) if 'nchapters' not in self.person or 'grade' not in self.person or 'certified' not in self.person: print "One of the three columns necessary for this plot is missing. Check person_course for: 'nchapters','grade', and 'certified'." return None ### Data data = self.person[['nchapters', 'grade', 'certified']].copy() chap_jmax = 0.75 grade_jmax = 0.005 data.nchapters = data.nchapters.apply(lambda x: x + chap_jmax * (np.random.sample() - 0.5)) data.grade = data.grade.apply(lambda x: x + grade_jmax * (np.random.sample())) data = data.dropna() certcut = self.person[self.person['certified'] == 1].grade.min() ### Plot fig = plt.figure(figsize=(12, 10)) ax1 = fig.add_subplot(1, 1, 1) #Non-Certs data[data.certified == 0].plot('nchapters', 'grade', style='.', color=xff.colors['neutral'], label=self.nickname, ax=ax1) #Certified data[data.certified == 1].plot('nchapters', 'grade', style='.', color=xff.colors['institute'], ax=ax1) ### Illustrations (labels) ncmax = self.person[self.person.certified == 1].nchapters.order( )[-20::].min() ### Funny, but this cuts off staff ax1.hlines(certcut, 0, ncmax + 1, lw=2) ax1.vlines(int(ncmax / 2), 0, certcut, lw=2) ax1.text(ncmax / 6, certcut - 0.05, '$Viewed$', fontsize=30, alpha=0.75) ax1.text(ncmax / 2 + (ncmax / 4), certcut - 0.05, '$Explored$', fontsize=30, alpha=0.75) ax1.text( ncmax / 2, 0.8, '$Certified$', fontsize=30, alpha=0.75, horizontalalignment='center', ) ### Plot Details ax1.set_xticklabels([r'$%0.f$' % x for x in ax1.get_xticks()]) ax1.set_yticklabels([r'$%0.1f$' % x for x in ax1.get_yticks()], fontsize=30) #ax1.legend(loc=4,prop={'size':28},frameon=False) ax1.set_xlim(0, ncmax + 1) ax1.set_ylim(0, 1.01) ### Generalized Plotting functions figsavename = self.figpath + 'scatter_grade_vs_nchapters_' + self.nickname.replace( '.', '_') xff.texify(fig, ax1, xlabel='Chapters Viewed', ylabel='Grade', gridb='y', figsavename=figsavename + '.png') #---------------------------------------------------------------- ### NVD3 Interactive http://nvd3.org/ if NVD3: data = data[(data.nchapters > 0) & (data.grade > 0)].dropna() randrows = np.random.choice(data.index.values, 2000) data = data.ix[randrows, :] X1 = data[data.certified == 0].nchapters.values Y1 = data[data.certified == 0].grade.values X2 = data[data.certified == 1].nchapters.values Y2 = data[data.certified == 1].grade.values #print X1,Y1 ### FIGURE from nvd3 import scatterChart ### Output File figsavename = self.figpath + 'interactive_scatter_grade_nchap_' + self.nickname + '.html' output_file = open(figsavename, 'w') print figsavename title = "Scatter Plot Grade vs Chapters Viewed: %s" % self._xdata.course_id chart = scatterChart(name=title, width=850, height=550, x_is_date=False, x_axis_format=".1f", y_axis_format=".1f") chart.set_containerheader("\n\n<h2>" + title + "</h2>\n\n") nb_element = len(X1) kwargs1 = {'shape': 'circle', 'size': '3'} kwargs2 = {'shape': 'circle', 'size': '3'} extra_serie = {"tooltip": {"y_start": "", "y_end": " calls"}} chart.add_serie(name="Participants", y=Y1, x=X1, extra=extra_serie, **kwargs1) chart.add_serie(name="Certified", y=Y2, x=X2, extra=extra_serie, **kwargs2) ### Final Output chart.buildhtml() output_file.write(chart.htmlcontent) #--------------------------------------- #close Html file output_file.close() return None
from nvd3 import scatterChart xs = [1, 2, 3, 4, 5] ys = [2, 3, 5, 7, 11] kwargs = {'shape': 'circle', 'size': '1'} chart = scatterChart(name='The first few primes', height=400, width=400) chart.add_serie(name="Primes", x=xs, y=ys, **kwargs) output_file = open('nvd3-1.html', 'w') chart.buildhtml() output_file.write(chart.htmlcontent) output_file.close()
for i in range(0, 101): xdata.append(i) x = i * 0.1 ydata.append(math.sin(math.pi * x)) ydata2.append(0.5 * math.cos(math.pi * x)) chart.add_serie(y=ydata, x=xdata, name="sine") chart.add_serie(y=ydata2, x=xdata, name="cose") chart.buildhtml() output_file.write(chart.htmlcontent) # --------------------------------------- type = "scatterChart" chart = scatterChart(name=type, height=350, date=False) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") nb_element = 50 xdata = [i + random.randint(1, 10) for i in range(nb_element)] ydata = [i * random.randint(1, 10) for i in range(nb_element)] ydata2 = map(lambda x: x * 2, ydata) ydata3 = map(lambda x: x * 5, ydata) kwargs1 = {"shape": "circle"} kwargs2 = {"shape": "cross"} kwargs3 = {"shape": "triangle-up"} # kwargs['size'] = True chart.add_serie(y=ydata, x=xdata, **kwargs1) chart.add_serie(y=ydata2, x=xdata, **kwargs2) chart.add_serie(y=ydata3, x=xdata, **kwargs3)
def grade_vs_nchapters(self,**kwargs): """ Scatter plot of final grade versus nchapters accessed. All points are jittered for clarity. Text labels are added to indicate subpopulations. Parameters ---------- NVD3 = False. If true, nvd3 interactive figure output. Output ------ Figures and respective formats. Returns ------- None """ NVD3 = kwargs.get('NVD3',False) if 'nchapters' not in self.person or 'grade' not in self.person or 'certified' not in self.person: print "One of the three columns necessary for this plot is missing. Check person_course for: 'nchapters','grade', and 'certified'." return None ### Data data = self.person[['nchapters','grade','certified']].copy() chap_jmax = 0.75 grade_jmax = 0.005 data.nchapters = data.nchapters.apply(lambda x: x + chap_jmax*(np.random.sample()-0.5)) data.grade = data.grade.apply(lambda x: x + grade_jmax*(np.random.sample())) data = data.dropna() certcut = self.person[self.person['certified']==1].grade.min() ### Plot fig = plt.figure(figsize=(12,10)) ax1 = fig.add_subplot(1,1,1) #Non-Certs data[data.certified==0].plot('nchapters','grade',style='.',color=xff.colors['neutral'],label=self.nickname,ax=ax1) #Certified data[data.certified==1].plot('nchapters','grade',style='.',color=xff.colors['institute'],ax=ax1) ### Illustrations (labels) ncmax = self.person[self.person.certified==1].nchapters.order()[-20::].min() ### Funny, but this cuts off staff ax1.hlines(certcut,0,ncmax+1,lw=2) ax1.vlines(int(ncmax/2),0,certcut,lw=2) ax1.text(ncmax/6,certcut-0.05,'$Viewed$',fontsize=30,alpha=0.75) ax1.text(ncmax/2+(ncmax/4),certcut-0.05,'$Explored$',fontsize=30,alpha=0.75) ax1.text(ncmax/2,0.8,'$Certified$',fontsize=30,alpha=0.75,horizontalalignment='center',) ### Plot Details ax1.set_xticklabels([r'$%0.f$' % x for x in ax1.get_xticks()]) ax1.set_yticklabels([r'$%0.1f$' % x for x in ax1.get_yticks()],fontsize=30) #ax1.legend(loc=4,prop={'size':28},frameon=False) ax1.set_xlim(0,ncmax+1) ax1.set_ylim(0,1.01) ### Generalized Plotting functions figsavename = self.figpath+'scatter_grade_vs_nchapters_'+self.nickname.replace('.','_') xff.texify(fig,ax1, xlabel='Chapters Viewed', ylabel='Grade', gridb='y', figsavename=figsavename+'.png') #---------------------------------------------------------------- ### NVD3 Interactive http://nvd3.org/ if NVD3: data = data[(data.nchapters>0) & (data.grade>0)].dropna() randrows = np.random.choice(data.index.values,2000) data = data.ix[randrows,:] X1 = data[data.certified==0].nchapters.values Y1 = data[data.certified==0].grade.values X2 = data[data.certified==1].nchapters.values Y2 = data[data.certified==1].grade.values #print X1,Y1 ### FIGURE from nvd3 import scatterChart ### Output File figsavename = self.figpath+'interactive_scatter_grade_nchap_'+self.nickname+'.html' output_file = open(figsavename, 'w') print figsavename title = "Scatter Plot Grade vs Chapters Viewed: %s" % self._xdata.course_id chart = scatterChart(name=title, width=850, height=550, x_is_date=False, x_axis_format=".1f", y_axis_format=".1f") chart.set_containerheader("\n\n<h2>" + title + "</h2>\n\n") nb_element = len(X1) kwargs1 = {'shape': 'circle', 'size': '3'} kwargs2 = {'shape': 'circle', 'size': '3'} extra_serie = {"tooltip": {"y_start": "", "y_end": " calls"}} chart.add_serie(name="Participants", y=Y1, x=X1, extra=extra_serie, **kwargs1) chart.add_serie(name="Certified", y=Y2, x=X2, extra=extra_serie, **kwargs2) ### Final Output chart.buildhtml() output_file.write(chart.htmlcontent) #--------------------------------------- #close Html file output_file.close() return None
ydata2 = map(lambda x: x * 2, ydata) tooltip_date = "%d %b %Y %H:%M:%S %p" extra_serie = {"tooltip": {"y_start": "There are ", "y_end": " calls"}, "date_format": tooltip_date} chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie) extra_serie = {"tooltip": {"y_start": "There are ", "y_end": " duration"}, "date_format": tooltip_date} chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie) chart.buildhtml() output_file.write(chart.htmlcontent) #--------------------------------------- type = "scatterChart" chart = scatterChart(name=type, height=350, date=False) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") nb_element = 50 xdata = [i + random.randint(1, 10) for i in range(nb_element)] ydata = [i * random.randint(1, 10) for i in range(nb_element)] ydata2 = [x * 2 for x in ydata] ydata3 = [x * 5 for x in ydata] kwargs1 = {'shape': 'circle', 'size': '1'} kwargs2 = {'shape': 'cross', 'size': '10'} kwargs3 = {'shape': 'triangle-up', 'size': '100'} extra_serie = {"tooltip": {"y_start": "", "y_end": " calls"}} chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie, **kwargs1) chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie, **kwargs2) chart.add_serie(name="serie 3", y=ydata3, x=xdata, extra=extra_serie, **kwargs3)
else: try: hor = float(line[field1]) dep = float(line[field2]) X.append([hor, dep]) except: pass X = np.asarray(X) #X = X[:400] kmeans = KMeans(n_clusters=num_clusters) kmeans.fit(X) centroids = kmeans.cluster_centers_ labels = kmeans.labels_ chart = scatterChart(name='scatterChart',margin_top=70, margin_bottom=200, height=800, width=1800) for j in range(0, num_clusters): globals()['centx%s' % j] = [] globals()['centy%s' % j] = [] for i in range(len(labels)): for j in range(0,num_clusters): if labels[i:i+1] == j: globals()['centx%s' % j].append(X[i][0]) globals()['centy%s' % j].append(X[i][1]) kwargs1 = {'shape': 'cross', 'size': '20', 'color': 'black'} for c in range(0, num_clusters): groupName = str('Cluster%s' % str(c+1)) chart.add_serie(name=groupName, y=globals()['centy%s' % c], x=globals()['centx%s' % c]) chart.add_serie(name="Centroids", y=centroids[:, 1], x=centroids[:, 0], **kwargs1)
chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie) extra_serie = { "tooltip": { "y_start": "There are ", "y_end": " duration" }, "date_format": tooltip_date } chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie) chart.buildcontent() output_file.write(chart.htmlcontent) #--------------------------------------- type = "scatterChart" chart = scatterChart(height=350, date=False, jquery_on_ready=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") nb_element = 50 xdata = [i + random.randint(1, 10) for i in range(nb_element)] ydata = [i * random.randint(1, 10) for i in range(nb_element)] ydata2 = [x * 2 for x in ydata] ydata3 = [x * 5 for x in ydata] kwargs1 = {'shape': 'circle', 'size': '1'} kwargs2 = {'shape': 'cross', 'size': '10'} kwargs3 = {'shape': 'triangle-up', 'size': '100'} extra_serie = {"tooltip": {"y_start": "", "y_end": " calls"}} chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie, **kwargs1) chart.add_serie(name="serie 2", y=ydata2,