def set_plot(self, new_plot: str) -> None: """ Switch the plot displayed to the one corresponding to parameter 'new_plot'. Preconditions: - plot in {"none", "canada_vs_carbon", "america_vs_carbon", "canada_vs_temp", "america_vs_temp"} """ self._plot_displayed = new_plot if new_plot == "canada_vs_carbon": self._plot_surface = \ plot.get_plot(self._data_points_canada_wildfire, self._data_points_canada_carbon, 'Number of Wildfires', 'Carbon Dioxide Emissions (kT)', "Canadian Wildfires vs Canadian CO2 Emissions") elif new_plot == "america_vs_carbon": self._plot_surface = \ plot.get_plot(self._data_points_america_wildfire, self._data_points_america_carbon, 'Number of Wildfires', 'Carbon Dioxide Emissions (kT)', "USA Wildfires vs American CO2 Emissions") elif new_plot == "canada_vs_temp": self._plot_surface = \ plot.get_plot(self._data_points_canada_wildfire, self._data_points_temp_deviance, 'Number of Wildfires', 'Temperature Deviance (°C)', "Canadian Wildfires vs North American Temperature Deviance") elif new_plot == "america_vs_temp": self._plot_surface = \ plot.get_plot(self._data_points_america_wildfire, self._data_points_temp_deviance, 'Number of Wildfires', 'Temperature Deviance (°C)', "USA Wildfires vs North American Temperature Deviance")
def command_plot(m): clear_arg_from_act(m) is_admin = True if m.from_user.id in admins else False try: plot_file_bytes = get_plot(data, extract_key(m.text), m.from_user.id, is_admin) except KeyErr as e: SEND_DATA(m.chat.id, 'text', e) return except Exception as e: SEND_DATA(m.chat.id, 'text', err_text) send_to_log('err in plot (' + str(e) + ') with\n' + m.text) return SEND_DATA(m.chat.id, 'photo', plot_file_bytes) return
def algorithm(): if request.method == 'GET': return render_template('algorithm.html') else: form_results = {} year = request.form.get('year') quarter = request.form.get('quarter') form_results['year'] = year form_results['quarter'] = quarter table_data = get_table(int(year), int(quarter)) form_results['table_data'] = table_data plot_data = get_plot(int(year), int(quarter)) form_results['plot_data'] = plot_data #return render_template('plot.html') return render_template('algorithm_response.html', form_results=form_results)
import numpy as np import qt import plot x = np.arange(-10, 10, 0.2) y = np.sinc(x) yerr = 0.1 * np.random.rand(len(x)) d = qt.Data() d.add_coordinate('x') d.add_coordinate('y') d.add_coordinate('yerr') d.create_file() d.add_data_point(x, y, yerr) p = plot.get_plot('error bar test plot', replace_if_exists=True) p = p.get_plot() p.add_trace(d['x'], d['y'], yerr=d['yerr']) p.update() #.run() # necessary if you've closed the window
import numpy as np import qt import plot import logging ####### Simple plot ####### x = np.arange(-10, 10, 0.2) y = np.sinc(x) p = plot.get_plot('sinc function plot') p = p.get_plot() p.clear() p.add_trace(x, y, lines=True, points=True, color='blue', title='sinc(x)') # See p.add_trace? for a complete list of options p.set_grid(True) p.set_xlabel('X value [radians]') p.set_ylabel('Y value') # Add another curve to the plot, on the right axis y2 = np.cos(x) *10 p.add_trace(x, y2, color='red', title='cos(x)', right=True) p.set_y2range(-25, 15) p.set_y2label('Y2 value')
x_vec = linspace(-2 * pi, 2 * pi, 150) qt.mstart() data = qt.Data(name='testmeasurement') data.add_coordinate('X') data.add_value('Y') data.create_file() # This plots the data as points are added. # In general however, it's better to plot your data in # an entirely separate process from the main qtlab instance # controlling your measurement hardware. # See other plotting examples and the "dataview" example. p = plot.get_plot('test measurement plot', replace_if_exists=True) p.add_data(data) p.set_default_labels() p.get_plot().set_xrange(-8,8) for x in x_vec: result = sinc(x) data.add_data_point(x, result) qt.msleep(0.05) # simulate a real measurement with this delay data.close_file() qt.mend() st = SettingsFile(data.get_filepath()) print '\n Get the list of instruments with "get_instruments()": \n'
# Divide the data into y vs t sweeps ############################################################################## # Can be done by using a value that is constant for the whole sweep sweeps = d.divide_into_sweeps('sweep_start_time') logging.info('sweeps based on a constant value: ' + str(sweeps)) # Or based on the direction of change of a coordinate sweeps = d.divide_into_sweeps('t') logging.info('sweeps based on the swept coordinate: ' + str(sweeps)) ############################################################################## # Plot each sweep separately ############################################################################## p = plot.get_plot(name='dataview example').get_plot() p.set_xlabel('t') p.set_ylabel('y') for sweep_start, sweep_end in sweeps: # Make a "shallow copy", i.e. only the mask of dd is independent of d. # This is because the indices in "sweeps" are relative # to the _unmasked_ rows of d so we don't want to change its mask # in each iteration. dd = d.copy() dd.mask_rows(slice(sweep_start, sweep_end), unmask_instead=True) # hide the other rows assert len(np.unique(dd['heater_current'])) == 1 heater_cur = dd['heater_current'][0]
x_vec = linspace(-2 * pi, 2 * pi, 150) qt.mstart() data = qt.Data(name='testmeasurement') data.add_coordinate('X') data.add_value('Y') data.create_file() # This plots the data as points are added. # In general however, it's better to plot your data in # an entirely separate process from the main qtlab instance # controlling your measurement hardware. # See other plotting examples and the "dataview" example. p = plot.get_plot('test measurement plot', replace_if_exists=True) p.add_data(data) p.set_default_labels() p.get_plot().set_xrange(-8, 8) for x in x_vec: result = sinc(x) data.add_data_point(x, result) qt.msleep(0.05) # simulate a real measurement with this delay data.close_file() qt.mend() st = SettingsFile(data.get_filepath()) print '\n Get the list of instruments with "get_instruments()": \n'
############################################################################## # Can be done by using a value that is constant for the whole sweep sweeps = d.divide_into_sweeps('sweep_start_time') logging.info('sweeps based on a constant value: ' + str(sweeps)) # Or based on the direction of change of a coordinate sweeps = d.divide_into_sweeps('t') logging.info('sweeps based on the swept coordinate: ' + str(sweeps)) ############################################################################## # Plot each sweep separately ############################################################################## p = plot.get_plot(name='dataview example').get_plot() p.set_xlabel('t') p.set_ylabel('y') for sweep_start, sweep_end in sweeps: # Make a "shallow copy", i.e. only the mask of dd is independent of d. # This is because the indices in "sweeps" are relative # to the _unmasked_ rows of d so we don't want to change its mask # in each iteration. dd = d.copy() dd.mask_rows(slice(sweep_start, sweep_end), unmask_instead=True) # hide the other rows assert len(np.unique(dd['heater_current'])) == 1 heater_cur = dd['heater_current'][0] p.add_trace(dd['t'], dd['y'],
def plot(self, start=None, end=None, time_since_start_of_day=False, flow=False, temperatures=True, resistances=False, pressures=False, turbo=False, compressor=False): ''' Plot statistics for the time range (start, end), specified as datetime objects, or alternatively, as strings in the "YY-MM-DD" format. If end is None, the current time is used. If start is None, the start of the previous cooldown before end is used. time_since_start_of_day means that the time axis will be given in hours since the beginning of the first day in the included range (makes it easier to figure out the corresponding time of day). Otherwise, it will be in hours since the first point. Returns the end points of the plotted timerange. ''' ends = [None, None] for i,t in enumerate([start, end]): if t == None: continue elif isinstance(t, datetime.datetime): ends[i] = t else: parsed = self.__parse_datestr(t) if parsed != None: ends[i] = parsed if i == 1: ends[i] += datetime.timedelta(0, 23*3600 + 59*60 + 59) else: raise Exception('%s is neither None, a datetime object, or a string in the "YY-MM-DD" format.' % str(t)) if ends[1] == None: ends[1] = datetime.datetime.now(tz.tzlocal()) if ends[0] == None: ends[0] = self.find_cooldown(near=ends[1])[0] logging.info('Plotting %s.', ends) import plot p = plot.get_plot('BlueFors stats').get_plot() p.clear() p.set_title('BlueFors stats from %s to %s' % (ends[0].strftime('%Y-%m-%d'), ends[1].strftime('%m-%d'))) p.set_xlabel('time (h)') p.set_ylog(True) quantities_to_plot = [] if flow: quantities_to_plot.append( ('flow (mmol/s)', self.get_flow(ends), 0, 5 ) ) if temperatures: for ch in self._tchannels: quantities_to_plot.append( ('T%s (K)' % ch, self.get_temperature(ch, ends), ch, 7 ) ) if resistances: for ch in self._rchannels: quantities_to_plot.append( ('R%s ({/Symbol O})' % ch, self.get_resistance(ch, ends), ch, 8 ) ) if pressures: for ch in self._pchannels: quantities_to_plot.append( ('P%s (mBar)' % ch, self.get_pressure(ch, ends), ch, 6 ) ) prefixes = [] if turbo: prefixes.append('turbo ') if compressor: prefixes.append('compressor ') for prefix in prefixes: for paramno, param_and_units in enumerate(self._params_in_common_format): param, units = param_and_units if param.startswith(prefix): quantities_to_plot.append( ('%s (%s)' % (param.replace('_',' '), units), getattr(self, 'get_%s' % param.replace(' ','_'))(ends), paramno, 9 if prefix.startswith('turbo') else 10 ) ) for title,pts,color,pointtype in quantities_to_plot: ref_time = datetime.datetime(ends[0].year, ends[0].month, ends[0].day, 0, 0, tzinfo=tz.tzlocal()) if time_since_start_of_day else ends[0] if len(pts) == 0: logging.warn('No %s data for the specified time period.', title) continue hours_since_beginning = np.array([ (t - ref_time).total_seconds() for t in pts[:,0] ]) / 3600. p.add_trace(hours_since_beginning, pts[:,1].astype(np.float), points=True, lines=True, color=color, pointtype=pointtype, title=title) p.update() p.run() return ends
import numpy as np import qt import plot x = np.arange(-10, 10, 0.2) y = np.sinc(x) yerr = 0.1*np.random.rand(len(x)) d = qt.Data() d.add_coordinate('x') d.add_coordinate('y') d.add_coordinate('yerr') d.create_file() d.add_data_point(x,y,yerr) p = plot.get_plot('error bar test plot', replace_if_exists=True) p = p.get_plot() p.add_trace(d['x'], d['y'], yerr=d['yerr']) p.update() #.run() # necessary if you've closed the window