def plot_bars(bar_list, tick_labels, tick_positions=None, x_label='', y_label='', title='', legend_names=[], loc=2):
    # plot values
    fig = plt.figure()
    fig.suptitle(title)
    ax = Subplot(fig, 111)
    ax = fig.add_subplot(ax)
    plt.ylabel(y_label)
    plt.xlabel(x_label)
    # plot each dataset
    width = .9/len(bar_list)                      # the width of the bars
    ind = np.array(range(len(bar_list[0])))
    color_list = ['#a6cee3', '#1f78b4', '#b2df8a', '#33a02c', '#fb9a99', '#e31a1c', '#fdbf6f', '#ff7f00', '#cab2d6', '#6a3d9a', '#ffff99', '#b15928']
    recs = []
    for i in range(len(bar_list)):
        recs.append(ax.bar(ind + (width * i), bar_list[i], width, color=color_list[i], linewidth=0))
    # calculate where the labels should go
    if tick_positions is not None:
        ax.set_xticks(np.array(tick_positions) + .5)
    else:
        ax.set_xticks(ind + .5)
    xtickNames = ax.set_xticklabels(tick_labels)
    # adjust how the axis shows
    ax.axis["bottom"].major_ticklabels.set_pad(30)
    ax.axis["bottom"].label.set_pad(20)
    ax.axis["bottom"].major_ticklabels.set_rotation(30)
    ax.axis["bottom"].major_ticks.set_visible(False)
    ax.axis["top"].set_visible(False)
    # add a legend
    if len(legend_names) == len(recs):
        legend_names = tuple([ln.title() for ln in legend_names])
        legend_colors = tuple(r[0] for r in recs)
        ax.legend( legend_colors, legend_names, frameon=False, loc=loc )
    
    plt.gcf().subplots_adjust(bottom=0.19)    # adjust the bottom of the plot
    plt.show()
Esempio n. 2
0
    def PlotVollmer(self, event): 

        #initialize the plot areas
        self.dataFigure.clf()
        axes = Subplot(self.dataFigure, 111, clip_on='True',xlim=(-0.1,1.05), ylim=(-0.1,1.05),autoscale_on='True',label='vollmer',aspect='equal', adjustable='box',anchor='SW')
        self.dataFigure.add_subplot(axes)
        axes.axis["right"].set_visible(False)
        axes.axis["top"].set_visible(False)
        axes.axis["bottom"].set_visible(False)
        axes.axis["left"].set_visible(False)



        try:
            sqrt3_2 = 0.866025  #m_sqrt(3)/2

            tr1 = Line2D((0,1),(0,0),c='black')
            axes.add_line(tr1)
            tr2 = Line2D((0,0.5),(0,sqrt3_2),c='black')
            axes.add_line(tr2)
            tr3 = Line2D((1,0.5),(0,sqrt3_2),c='black')
            axes.add_line(tr3)



            for i in [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]:
                diag = Line2D((i/2,1.0-i/2),(sqrt3_2*i,sqrt3_2*i),c='grey',lw=0.5)
                axes.add_line(diag)
                diag2 = Line2D((i/2,i),(sqrt3_2*i,0),c='grey',lw=0.5)
                axes.add_line(diag2)
                diag3 = Line2D((i,i+(1-i)/2),(0,sqrt3_2-sqrt3_2*i),c='grey',lw=0.5)
                axes.add_line(diag3)


            axes.text(-0.08,-0.05,'Point',family='sans-serif',size=self.fontSize,horizontalalignment='left' )
            axes.text(0.97,-0.05,'Girdle',family='sans-serif',size=self.fontSize,horizontalalignment='left' )
            axes.text(0.5,0.88,'Random',family='sans-serif',size=self.fontSize,horizontalalignment='center' )

            # label axes values
            for i in [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]:
                axes.text((1-i)/2, sqrt3_2*(1-i)-0.01, '%d' % (i*100), family='sans-serif', size=self.fontSize, horizontalalignment='right', color='grey', rotation='60')
                axes.text(i, -0.02,'%d' % (i*100), family='sans-serif', size=self.fontSize, horizontalalignment='center', verticalalignment='top', color='grey')
                axes.text(1.0-i/2, sqrt3_2*i-0.01,'%d' % (i*100) , family='sans-serif', size=self.fontSize, horizontalalignment='left', color='grey', rotation='-60')


            # ternary plot (from wikipedia)
            # P = (0,0)
            # G = (1,0)
            # R = (1/2, sqrt(3)/2)
            # given (P,G,R):
            # x = G + R/2
            # y = (sqrt(3)/2) * R

            if len(self.idxPlan) == 0 and len(self.idxLin) == 0: # in case we have only one one opened file but it is not checked
                raise AttributeError
            else:
                for i in range(len(self.idxPlan)):
                    x = self.PeigenList[i]["G"] + (self.PeigenList[i]["R"] / 2)
                    y = self.PeigenList[i]["R"] * sqrt3_2
                    axes.plot(x,y, self.PProps[i]["PoleSymb"], c=self.PProps[i]["PolColor"], ms=self.PProps[i]["polespin"],label='%s n=%d' % (self.Pname[i],self.Pndata[i]))

                for j in range(len(self.idxLin)):
                    x = self.LeigenList[j]["G"] + (self.LeigenList[j]["R"] / 2)
                    y = self.LeigenList[j]["R"] * sqrt3_2
                    axes.plot(x,y, self.LProps[j]["LineSymb"], c=self.LProps[j]["LinColor"], ms=self.LProps[j]["linespin"],label='%s n=%d' % (self.Lname[j],self.Lndata[j]))


            axes.legend(bbox_to_anchor=(0.97, 0.8), loc=2, prop=FontProperties(size=self.fontSize),numpoints=1)

            axes.set_xlim(-0.1,1.05)
            axes.set_ylim(-0.1,1.05)
            self.dataCanvas.draw()

        except AttributeError:
            self.dataFigure.clf()
            dlg = wx.MessageDialog(None, _('No file(s) selected (checked).\n\n'), _('Oooops!'), wx.OK|wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            pass
Esempio n. 3
0
    def PlotFlinn(self, event): 

        #initialize the plot areas
        self.dataFigure.clf()
        axes = Subplot(self.dataFigure, 111, clip_on='True',xlim=(-0.2,7.2), ylim=(-0.2,7.2),autoscale_on='True',xlabel='ln(S2/S3)',ylabel='ln(S1/S2)',label='flinn',aspect='equal', adjustable='box',anchor='W')
        self.dataFigure.add_subplot(axes)
        axes.axis["right"].set_visible(False)
        axes.axis["top"].set_visible(False)

        try:
            # plot lines of K
            for i in [0.2, 0.5, 1.0, 2.0, 5.0]:
                if i <= 1.0:
                    diag = Line2D((0,7.0),(0,(i*7.0)),c='grey',lw=0.5)
                    axes.add_line(diag)
                else:
                    diag = Line2D((0,(7.0/i)),(0,7.0),c='grey',lw=0.5)
                    axes.add_line(diag)

            # plot lines of C
            for j in [2,4,6]:
                diag2 = Line2D((0,j),(j,0),c='grey',lw=0.5)
                axes.add_line(diag2)

            # texts
            axes.text(6.25,0.05,'K = 0',family='sans-serif',size=self.fontSize,horizontalalignment='left',color='grey')
            axes.text(0.15,6.1,'K = inf.',family='sans-serif',size=self.fontSize,horizontalalignment='left',color='grey',rotation='vertical')
            axes.text(6.45,6.4,'K = 1',family='sans-serif',size=self.fontSize,horizontalalignment='center',color='grey',rotation='45')
            axes.text(3.2,6.4,'K = 2',family='sans-serif',size=self.fontSize,horizontalalignment='center',color='grey',rotation='63.5')
            axes.text(1.2,6.4,'K = 5',family='sans-serif',size=self.fontSize,horizontalalignment='center',color='grey',rotation='78.7')
            axes.text(6.4,3.1,'K = 0.5',family='sans-serif',size=self.fontSize,horizontalalignment='center',color='grey',rotation='26.6')
            axes.text(6.5,1.3,'K = 0.2',family='sans-serif',size=self.fontSize,horizontalalignment='center',color='grey',rotation='11.3')
            axes.text(2.6,3.35,'C = 6',family='sans-serif',size=self.fontSize,horizontalalignment='center',color='grey',rotation='-45')
            axes.text(1.75,2.2,'C = 4',family='sans-serif',size=self.fontSize,horizontalalignment='center',color='grey',rotation='-45')

            axes.text(3.5,3.75,'Girdle/Cluster Transition',family='sans-serif',size=self.fontSize,horizontalalignment='left',verticalalignment='bottom',color='grey',rotation='45')
            axes.text(6.5,7.2,'CLUSTERS',family='sans-serif',size=self.fontSize,horizontalalignment='right',verticalalignment='bottom',color='grey')
            axes.text(7.2,6.5,'GIRDLES',family='sans-serif',size=self.fontSize,horizontalalignment='left',verticalalignment='top',color='grey',rotation='-90')


            # plot the selected (checked) files
            # propsPList = [pdata, itemName, PolColor, symbPoles, polespin,...
            # propsLList = [pdata, itemName, LinColor, LineSymb, linespin,...

            if len(self.idxPlan) == 0 and len(self.idxLin) == 0: # in case we have only one one opened file but it is not checked
                raise AttributeError
            else:
                for i in range(len(self.idxPlan)):
                    axes.plot(self.PeigenList[i]["K_x"],self.PeigenList[i]["K_y"], self.PProps[i]["PoleSymb"], c=self.PProps[i]["PolColor"], ms=self.PProps[i]["polespin"], label='%s n=%d' % (self.Pname[i],self.Pndata[i]))

                for j in range(len(self.idxLin)):
                    axes.plot(self.LeigenList[j]["K_x"],self.LeigenList[j]["K_y"], self.LProps[j]["LineSymb"], c=self.LProps[j]["LinColor"], ms=self.LProps[j]["linespin"], label='%s n=%d' % (self.Lname[j],self.Lndata[j]))

            axes.legend(bbox_to_anchor=(1.1, 1), loc=2, prop=FontProperties(size='small'),numpoints=1)

            #set the axes limits and draws the stuff
            axes.set_xlim(0.0,7.2)
            axes.set_ylim(0.0,7.2)
            self.dataCanvas.draw()

        except AttributeError:
            self.dataFigure.clf()
            dlg = wx.MessageDialog(None, 'No file(s) selected (checked).\n\n', 'Oooops!', wx.OK|wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            pass