Пример #1
0
    def ppSubPlot(self, x, y, platform, color, xParm, yParm, ax, startTime):
        '''
        Given names of platform, x & y paramters add a subplot to figure fig.
        '''
        xmin, xmax, xUnits = self._getAxisInfo(platform, xParm)
        ymin, ymax, yUnits = self._getAxisInfo(platform, yParm)

        # Make the plot
        ax.set_xlim(round_to_n(xmin, 1), round_to_n(xmax, 1))
        ax.set_ylim(round_to_n(ymin, 1), round_to_n(ymax, 1))

        if self.args.xLabel == '':
            ax.set_xticks([])
        elif self.args.xLabel:
            ax.set_xlabel(self.args.xLabel)
        else:
            ax.set_xlabel('%s (%s)' % (xParm, xUnits))

        if self.args.yLabel == '':
            ax.set_yticks([])
        elif self.args.yLabel:
            ax.set_ylabel(self.args.yLabel)
        else:
            ax.set_ylabel('%s (%s)' % (yParm, yUnits))

        ax.scatter(x, y, marker='.', s=10, c='k', lw=0, clip_on=True)
        ax.text(0.0,
                1.0,
                platform,
                transform=ax.transAxes,
                color=color,
                horizontalalignment='left',
                verticalalignment='top')

        return ax
Пример #2
0
    def ppSubPlot(self, x, y, platform, color, xParm, yParm, ax, startTime):
        '''
        Given names of platform, x & y paramters add a subplot to figure fig.
        '''
        xmin, xmax, xUnits = self._getAxisInfo(platform, xParm)
        ymin, ymax, yUnits = self._getAxisInfo(platform, yParm)

        # Make the plot 
        ax.set_xlim(round_to_n(xmin, 1), round_to_n(xmax, 1))
        ax.set_ylim(round_to_n(ymin, 1), round_to_n(ymax, 1))

        if self.args.xLabel == '':
            ax.set_xticks([])
        elif self.args.xLabel:
            ax.set_xlabel(self.args.xLabel)
        else:
            ax.set_xlabel('%s (%s)' % (xParm, xUnits))

        if self.args.yLabel == '':
            ax.set_yticks([])
        elif self.args.yLabel:
            ax.set_ylabel(self.args.yLabel)
        else:
            ax.set_ylabel('%s (%s)' % (yParm, yUnits))

        ax.scatter(x, y, marker='.', s=10, c='k', lw = 0, clip_on=True)
        ax.text(0.0, 1.0, platform, transform=ax.transAxes, color=color, horizontalalignment='left', verticalalignment='top')

        return ax
Пример #3
0
    def ppSubPlotColor(self, x_ids, y_ids, platform, color, xParm, yParm, ax):
        '''
        Given names of platform, x & y paramter ids return a categorically colored subplot
        See: https://gist.github.com/jakevdp/8a992f606899ac24b711
        and https://stackoverflow.com/questions/28033046/matplotlib-scatter-color-by-categorical-factors?answertab=active#tab-top
        '''
        all_labels = (Resource.objects.using(self.args.database).filter(
            resourcetype__name__contains=self.args.groupName).order_by(
                'value').distinct().values_list('value', flat=True))
        if not all_labels:
            raise ValueError(
                f'Found no resources containing --groupName {self.args.groupName}'
            )
        total_num_colors = len(all_labels)

        colors = {}
        if total_num_colors < 11:
            ck = plt.cm.Vega10
        elif total_num_colors < 21:
            ck = plt.cm.Vega20
        else:
            cl = plt.cm.viridis

        for b, c in zip(
                all_labels,
                ck(np.arange(0, ck.N, ck.N / total_num_colors, dtype=int))):
            colors[b] = c

        mprs = MeasuredParameterResource.objects.using(
            self.args.database).filter(
                resource__resourcetype__name__contains=self.args.groupName,
                measuredparameter__id__in=(x_ids + y_ids))

        if self.args.verbose:
            print(f'{mprs.count()} mprs for {self.args.groupName}')

        for label in all_labels:
            xy_data = defaultdict(list)
            for mpr in mprs.filter(resource__value=label):
                xy_data[mpr.measuredparameter.parameter.name].append(
                    mpr.measuredparameter.datavalue)
            if xy_data:
                if self.args.verbose:
                    print(
                        f'{len(xy_data[xParm])} points for {label}, color = {colors[label]}'
                    )
                ax.scatter(xy_data[xParm],
                           xy_data[yParm],
                           marker='.',
                           s=15,
                           label=label,
                           color=colors[label],
                           clip_on=True)

        ax.legend(loc='upper left', fontsize=7)
        ax.text(1.0,
                1.0,
                platform,
                transform=ax.transAxes,
                color=color,
                horizontalalignment='right',
                verticalalignment='top')

        xmin, xmax, xUnits = self._getAxisInfo(platform, xParm)
        ymin, ymax, yUnits = self._getAxisInfo(platform, yParm)

        ax.set_xlim(round_to_n(xmin, 1), round_to_n(xmax, 1))
        ax.set_ylim(round_to_n(ymin, 1), round_to_n(ymax, 1))

        if self.args.xLabel == '':
            ax.set_xticks([])
        elif self.args.xLabel:
            ax.set_xlabel(self.args.xLabel)
        else:
            ax.set_xlabel('%s (%s)' % (xParm, xUnits))

        if self.args.yLabel == '':
            ax.set_yticks([])
        elif self.args.yLabel:
            ax.set_ylabel(self.args.yLabel)
        else:
            ax.set_ylabel('%s (%s)' % (yParm, yUnits))

        return ax
Пример #4
0
    def ppSubPlotColor(self, x_ids, y_ids, platform, color, xParm, yParm, ax):
        '''
        Given names of platform, x & y paramter ids return a categorically colored subplot
        See: https://gist.github.com/jakevdp/8a992f606899ac24b711
        and https://stackoverflow.com/questions/28033046/matplotlib-scatter-color-by-categorical-factors?answertab=active#tab-top
        '''
        all_labels = (Resource.objects.using(self.args.database)
                        .filter(resourcetype__name__contains=self.args.groupName)
                        .order_by('value')
                        .distinct()
                        .values_list('value', flat=True))
        if not all_labels:
            raise ValueError(f'Found no resources containing --groupName {self.args.groupName}')
        total_num_colors = len(all_labels)

        colors = {}
        if total_num_colors < 11:
            ck = plt.cm.Vega10
        elif total_num_colors < 21:
            ck = plt.cm.Vega20
        else:
            cl = plt.cm.viridis

        for b, c in zip(all_labels, ck(np.arange(0, ck.N, ck.N/total_num_colors, dtype=int))):
            colors[b] = c

        mprs = MeasuredParameterResource.objects.using(self.args.database).filter(
                        resource__resourcetype__name__contains=self.args.groupName,
                        measuredparameter__id__in=(x_ids + y_ids))

        if self.args.verbose:
            print(f'{mprs.count()} mprs for {self.args.groupName}')

        for label in all_labels:
            xy_data = defaultdict(list)
            for mpr in mprs.filter(resource__value=label):
                xy_data[mpr.measuredparameter.parameter.name].append(mpr.measuredparameter.datavalue)
            if xy_data: 
                if self.args.verbose:
                    print(f'{len(xy_data[xParm])} points for {label}, color = {colors[label]}')
                ax.scatter(xy_data[xParm], xy_data[yParm], marker='.', s=15, label=label, 
                           color=colors[label], clip_on=True)

        ax.legend(loc='upper left', fontsize=7)
        ax.text(1.0, 1.0, platform, transform=ax.transAxes, color=color, horizontalalignment='right', verticalalignment='top')

        xmin, xmax, xUnits = self._getAxisInfo(platform, xParm)
        ymin, ymax, yUnits = self._getAxisInfo(platform, yParm)

        ax.set_xlim(round_to_n(xmin, 1), round_to_n(xmax, 1))
        ax.set_ylim(round_to_n(ymin, 1), round_to_n(ymax, 1))

        if self.args.xLabel == '':
            ax.set_xticks([])
        elif self.args.xLabel:
            ax.set_xlabel(self.args.xLabel)
        else:
            ax.set_xlabel('%s (%s)' % (xParm, xUnits))

        if self.args.yLabel == '':
            ax.set_yticks([])
        elif self.args.yLabel:
            ax.set_ylabel(self.args.yLabel)
        else:
            ax.set_ylabel('%s (%s)' % (yParm, yUnits))

        return ax