def main(): """ Main interface """ parser = _create_parser() args = parser.parse_args() if len(sys.argv) == 1: parser.print_usage() parser.exit(status=1) elif args.countries: print("\n".join(map(str, data.countries()))) sys.exit() elif args.states: print("\n".join(map(str, data.states()))) sys.exit() region = data.read(args.region) if not region: print(f"Region '{args.region}' not found.") sys.exit(1) title = f"COVID-19 Infections ({region})" with tempfile.NamedTemporaryFile(mode="w") as datfile: for stats in region.daily_stats(): datfile.write(f"{stats.date}\t{stats.cases}\t{stats.avg}\n") datfile.flush() gnuplot = Gnuplot("./covid.gp", args.terminal, args.output) gnuplot.set_var("datfile", datfile.name) gnuplot.set_var("title", title) gnuplot.run()
def plot_orbit(self, plotfile, nsamp=100): coeffs = self.coeffs[0].T coords = self.coords / 1e3 t = self.time time = np.linspace(self.t_start, self.t_stop, nsamp) if self.centered: time_cent = time - self.t_mean poly = np.asarray([ np.polyval(coeffs[ii, :], time_cent) + mean_coords[ii] for ii in range(3) ]).T else: poly = np.asarray( [np.polyval(coeffs[ii, :], time) for ii in range(3)]).T poly /= 1e3 gpt = Gnuplot() gpt.output(plotfile, term="pngcairo", fontsize=8) gpt.axis_format("x", "") gpt.margins(bmargin=3.5) gpt("set tics font ',8'") gpt.multiplot(3, portrait=True, title="Fit of orbital vectors - " "degree of polynom: {}".format(self.deg)) ylabels = ("X [km]", "Y [km]", "Z [km]") for ii in range(3): gpt.ylabel(ylabels[ii]) points = gpt.data(t, coords[:, ii], title="Orbital coordinates", vith=linedef(point_type="empty_circle")) fit = gpt.data(time, poly[:, ii], title="Fitted polynom", vith="lines") if ii == 2: gpt("set format x") gpt.xlabel("Time [s]") gpt.plot(points, fit)
def gnuplot(f, *between): ''' Plot the function f within the optional limits *between ''' # Create an instance of the gnuplot class graph = Gnuplot() # Get the full file name and root_file_name (excluding extension) file_name, root_file_name = graph.file_name, graph.root_file_name # Plot the function graph.plot_function(f, *between) # Return a string / html representation of the graph return StrWithHtml('Image saved to ' + file_name, '''<img src="{}.svg" style="width: 100%" />'''.format(root_file_name))
def gnuplot(self, reg): ##################################################################### "plot with gnuplot" ##################################################################### if not self.__dict__.has_key('gp'): self.gp = Gnuplot() CQLRIO.DumpSamples('samples.dat', self.reg) if self.p.GetDimensions() == 1: CQLRIO.Distrib(reg) self.plot_to_file('distrib.dat', 100) self.gp.send('load "clop.gpi"') elif self.p.GetDimensions() == 2: CQLRIO.Distrib(reg) self.plot_to_file_2d('distrib.dat', 40) self.gp.send('load "samples2d.gpi"')
def _plot_non_consecutive_graph(self, graph_type): """TODO: Docstring for _plot_non_consecutive_graph. :returns: TODO """ cuts = Cut.all_cuts(self.cube) with open('output/detailed_output.csv', 'a', newline='') as csvfile: writer = csv.writer(csvfile) writer.writerow([graph_type]) writer.writerow(['filename', 'dependant', 'parameters']) for i, cut in enumerate(cuts): self.cube.populate_cut(cut) with Gnuplot() as plot: plot.output = "%s_cut_%d" % (graph_type, i) plot.xlabel = cut.dep plot.benchdata = self._format_data_for_gnuplot( cut, graph_type) plot.run() writer.writerow( [plot.output, cut.dep, cut.parameters.items()])
def new_gnuplot(self, reg): ##################################################################### "create a new gnuplot window" ##################################################################### self.gp = Gnuplot() self.gnuplot(reg)