def replace_spectro_fig(self, rays_to_plot, var_x, factor_x, xrange, title, color): try: beam = ShadowBeam() beam._beam.rays = rays_to_plot ticket = beam._beam.histo1(var_x, nbins=self.number_of_bins, xrange=xrange, nolost=self.rays, ref=self.weight_column_index) if self.weight_column_index != 0: self.spectro_plot_canvas.setGraphYLabel( "Number of rays weighted by " + ShadowPlot.get_shadow_label(self.weight_column_index)) else: self.spectro_plot_canvas.setGraphYLabel("Number of Rays") histogram = ticket['histogram_path'] bins = ticket['bin_path'] * factor_x self.spectro_plot_canvas.addCurve(bins, histogram, title, symbol='', color=color, replace=False) #'+', '^', ',' except Exception as e: print(e) raise Exception("Data not plottable: No good rays or bad content")
def plot_histo(self, beam, col, nbins=100, ref=23, title="", xtitle="", ytitle="", histo_index=0, scan_variable_name="Variable", scan_variable_value=0, offset=0.0, xrange=None, show_reference=True, add_labels=True, has_colormap=True, colormap=cm.rainbow): factor=ShadowPlot.get_factor(col, conv=self.workspace_units_to_cm) if histo_index==0 and xrange is None: ticket = beam._beam.histo1(col, xrange=None, nbins=nbins, nolost=1, ref=ref) fwhm = ticket['fwhm'] xrange = ticket['xrange'] centroid = get_average(ticket['histogram'], ticket['bin_center']) if not fwhm is None: xrange = [centroid - 2*fwhm , centroid + 2*fwhm] ticket = beam._beam.histo1(col, xrange=xrange, nbins=nbins, nolost=1, ref=ref) if not ytitle is None: ytitle = ytitle + ' weighted by ' + ShadowPlot.get_shadow_label(ref) histogram = ticket['histogram_path'] bins = ticket['bin_path']*factor histogram_stats = ticket['histogram'] bins_stats = ticket['bin_center'] sigma = get_sigma(histogram_stats, bins_stats)*factor fwhm = sigma*2.35 if ticket['fwhm'] is None else ticket['fwhm']*factor centroid = get_average(histogram_stats, bins_stats)*factor peak_intensity = numpy.average(histogram_stats[numpy.where(histogram_stats>=numpy.max(histogram_stats)*0.90)]) integral_intensity = numpy.sum(histogram_stats) rcParams['axes.formatter.useoffset']='False' self.set_xrange(bins) self.set_labels(title=title, xlabel=xtitle, ylabel=scan_variable_name, zlabel=ytitle) self.add_histo(scan_variable_value, histogram, has_colormap, colormap, histo_index) return HistogramData(histogram=histogram_stats, bins=bins_stats, xrange=xrange, fwhm=fwhm, sigma=sigma, centroid=centroid, peak_intensity=peak_intensity, integral_intensity=integral_intensity)
def plot_histo(self, beam, col, nbins=100, title="", xtitle="", ytitle="", histo_index=0, scan_variable_name="Variable", scan_variable_value=0, offset=0.0, xrange=None, show_reference=True, add_labels=True, has_colormap=True, colormap=cm.rainbow): factor = ShadowPlot.get_factor(col, conv=self.workspace_units_to_cm) if histo_index == 0 and xrange is None: ticket = beam._beam.histo1(col, xrange=None, nbins=nbins, nolost=1, ref=23) fwhm = ticket['fwhm'] xrange = ticket['xrange'] centroid = xrange[0] + (xrange[1] - xrange[0]) * 0.5 if not fwhm is None: xrange = [centroid - 2 * fwhm, centroid + 2 * fwhm] ticket = beam._beam.histo1(col, xrange=xrange, nbins=nbins, nolost=1, ref=23) if not ytitle is None: ytitle = ytitle + ' weighted by ' + ShadowPlot.get_shadow_label(23) histogram = ticket['histogram_path'] bins = ticket['bin_path'] * factor histogram_stats = ticket['histogram'] bins_stats = ticket['bin_center'] fwhm = ticket['fwhm'] sigma = get_sigma(histogram_stats, bins_stats) * factor fwhm = sigma * 2.35 if fwhm is None else fwhm * factor peak_intensity = numpy.average(histogram_stats[numpy.where( histogram_stats >= numpy.max(histogram_stats) * 0.85)]) if histo_index == 0 and show_reference: h_title = "Reference" else: h_title = scan_variable_name + ": " + str(scan_variable_value) color = "#000000" import matplotlib matplotlib.rcParams['axes.formatter.useoffset'] = 'False' if histo_index == 0: offset = int(peak_intensity * 0.3) self.plot_canvas.addCurve(bins, histogram + offset * histo_index, h_title, symbol='', color=color, xlabel=xtitle, ylabel=ytitle, replace=False) #'+', '^', ',' if add_labels: self.plot_canvas._backend.ax.text(xrange[0] * factor * 1.05, offset * histo_index * 1.05, h_title) if not xtitle is None: self.plot_canvas.setGraphXLabel(xtitle) if not ytitle is None: self.plot_canvas.setGraphYLabel(ytitle) if not title is None: self.plot_canvas.setGraphTitle(title) for label in self.plot_canvas._backend.ax.yaxis.get_ticklabels(): label.set_color('white') label.set_fontsize(1) self.plot_canvas.setActiveCurveColor(color="#00008B") self.plot_canvas.setDrawModeEnabled(True, 'rectangle') self.plot_canvas.setInteractiveMode('zoom', color='orange') self.plot_canvas.resetZoom() self.plot_canvas.replot() self.plot_canvas.setGraphXLimits(xrange[0] * factor, xrange[1] * factor) self.plot_canvas.setActiveCurve(h_title) self.plot_canvas.setDefaultPlotLines(True) self.plot_canvas.setDefaultPlotPoints(False) self.plot_canvas.getLegendsDockWidget().setFixedHeight(510) self.plot_canvas.getLegendsDockWidget().setVisible(True) self.plot_canvas.addDockWidget(Qt.RightDockWidgetArea, self.plot_canvas.getLegendsDockWidget()) return HistogramData(histogram_stats, bins_stats, offset, xrange, fwhm, sigma, peak_intensity)
def replace_spectro_fig(self, rays_to_plot, var_x, factor_x, xrange, title, color): try: beam = ShadowBeam() beam._beam.rays = rays_to_plot ticket = beam._beam.histo1(var_x, nbins=self.number_of_bins, xrange=xrange, nolost=self.rays, ref=self.weight_column_index) if self.weight_column_index != 0: self.spectro_plot_canvas.setGraphYLabel("Number of rays weighted by " + ShadowPlot.get_shadow_label(self.weight_column_index)) else: self.spectro_plot_canvas.setGraphYLabel("Number of Rays") histogram = ticket['histogram_path'] bins = ticket['bin_path']*factor_x self.spectro_plot_canvas.addCurve(bins, histogram, title, symbol='', color=color, replace=False) #'+', '^', ',' except Exception as e: print(e) raise Exception("Data not plottable: No good rays or bad content")