def _plot(self, a, key, title, gx, gy, num_x, num_y): logger.debug('Plotting: %s', key) pp.rcParams['figure.figsize'] = (self._image_width / 300, self._image_height / 300) pp.title(title) # Interpolate the data rbf = Rbf(a['x'], a['y'], a[key], function='linear') z = rbf(gx, gy) z = z.reshape((num_y, num_x)) # Render the interpolated data to the plot pp.axis('off') # begin color mapping if 'min' in self.thresholds.get(key, {}): vmin = self.thresholds[key]['min'] logger.debug('Using min threshold from thresholds: %s', vmin) else: vmin = min(a[key]) logger.debug('Using calculated min threshold: %s', vmin) if 'max' in self.thresholds.get(key, {}): vmax = self.thresholds[key]['max'] logger.debug('Using max threshold from thresholds: %s', vmax) else: vmax = max(a[key]) logger.debug('Using calculated max threshold: %s', vmax) norm = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax, clip=True) mapper = cm.ScalarMappable(norm=norm, cmap='RdYlBu_r') # end color mapping image = pp.imshow(z, extent=(0, self._image_width, self._image_height, 0), cmap='RdYlBu_r', alpha=0.5, zorder=100, vmin=vmin, vmax=vmax) pp.colorbar(image) pp.imshow(self._layout, interpolation='bicubic', zorder=1, alpha=1) labelsize = FontManager.get_default_size() * 0.4 # begin plotting points for idx in range(0, len(a['x'])): if (a['x'][idx], a['y'][idx]) in self._corners: continue pp.plot(a['x'][idx], a['y'][idx], marker='o', markeredgecolor='black', markeredgewidth=1, markerfacecolor=mapper.to_rgba(a[key][idx]), markersize=6) pp.text(a['x'][idx], a['y'][idx] - 30, a['ap'][idx], fontsize=labelsize, horizontalalignment='center') # end plotting points fname = '%s_%s.png' % (key, self._title) logger.info('Writing plot to: %s', fname) pp.savefig(fname, dpi=300) pp.close('all')
def _plot(self, a, key, title, gx, gy, num_x, num_y): if key not in a: logger.info("Skipping {} due to insufficient data".format(key)) return if not len(a['x']) == len(a['y']) == len(a[key]): logger.info("Skipping {} because data has holes".format(key)) return logger.debug('Plotting: %s', key) pp.rcParams['figure.figsize'] = ( self._image_width / 300, self._image_height / 300 ) fig, ax = pp.subplots() ax.set_title(title) if 'min' in self.thresholds.get(key, {}): vmin = self.thresholds[key]['min'] logger.debug('Using min threshold from thresholds: %s', vmin) else: vmin = min(a[key]) logger.debug('Using calculated min threshold: %s', vmin) if 'max' in self.thresholds.get(key, {}): vmax = self.thresholds[key]['max'] logger.debug('Using max threshold from thresholds: %s', vmax) else: vmax = max(a[key]) logger.debug('Using calculated max threshold: %s', vmax) logger.info("{} has range [{},{}]".format(key, vmin, vmax)) # Interpolate the data only if there is something to interpolate if vmin != vmax: rbf = Rbf( a['x'], a['y'], a[key], function='linear' ) z = rbf(gx, gy) z = z.reshape((num_y, num_x)) else: # Uniform array with the same color everywhere # (avoids interpolation artifacts) z = numpy.ones((num_y, num_x))*vmin # Render the interpolated data to the plot ax.axis('off') # begin color mapping norm = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax, clip=True) mapper = cm.ScalarMappable(norm=norm, cmap=self._cmap) # end color mapping image = ax.imshow( z, extent=(0, self._image_width, self._image_height, 0), alpha=0.5, zorder=100, cmap=self._cmap, vmin=vmin, vmax=vmax ) # Draw contours if requested and meaningful in this plot if self._contours is not None and vmin != vmax: CS = ax.contour(z, colors='k', linewidths=1, levels=self._contours, extent=(0, self._image_width, self._image_height, 0), alpha=0.3, zorder=150, origin='upper') ax.clabel(CS, inline=1, fontsize=6) cbar = fig.colorbar(image) # Print only one ytick label when there is only one value to be shown if vmin == vmax: cbar.set_ticks([vmin]) # Draw floorplan itself to the lowest layer with full opacity ax.imshow(self._layout, interpolation='bicubic', zorder=1, alpha=1) labelsize = FontManager.get_default_size() * 0.4 if(self._showpoints): # begin plotting points for idx in range(0, len(a['x'])): if (a['x'][idx], a['y'][idx]) in self._corners: continue ax.plot( a['x'][idx], a['y'][idx], zorder=200, marker='o', markeredgecolor='black', markeredgewidth=1, markerfacecolor=mapper.to_rgba(a[key][idx]), markersize=6 ) ax.text( a['x'][idx], a['y'][idx] - 30, a['ap'][idx], fontsize=labelsize, horizontalalignment='center' ) # end plotting points fname = '%s_%s.png' % (key, self._title) logger.info('Writing plot to: %s', fname) pp.savefig(fname, dpi=300) pp.close('all')
def fontsize(idx, default=FontManager.get_default_size()): coeff = p.nodes[idx]["freq"] / p.molecules size = default * coeff * ax_coeff return size