def plot_ApplevsGoogle_1(): plotname = inspect.stack()[0][3][5:] pandas_bokeh.output_file(os.path.join(PLOT_DIR, f"{plotname}.html")) df = df_stocks() plot = df.plot_bokeh(kind="line")
def test_mapplot(df_mapplot): "Mapplot test" kwargs = dict( x="longitude", y="latitude", hovertool_string="""<h2> @{name} </h2> <h3> Population: @{pop_max} </h3>""", tile_provider="STAMEN_TERRAIN_RETINA", size="size", figsize=(900, 600), title="World cities with more than 1.000.000 inhabitants", show_figure=False, ) p_map = df_mapplot.plot_bokeh(kind="map", **kwargs) p_map_accessor = df_mapplot.plot_bokeh.map(**kwargs) p_map_pandas_backend = df_mapplot.plot(kind="map", **kwargs) p_map_accessor_pandas_backend = df_mapplot.plot.map(**kwargs) layout = pandas_bokeh.plot_grid([[p_map, p_map_accessor]], plot_width=450, plot_height=300, show_plot=False) pandas_bokeh.output_file(os.path.join(DIRECTORY, "Plots", "Mapplot.html")) pandas_bokeh.save(layout)
def plot_Scatterplot(): plotname = inspect.stack()[0][3][5:] pandas_bokeh.output_file(os.path.join(PLOT_DIR, f"{plotname}.html")) df = df_iris() df = df.sample(frac=1) #Create Bokeh-Table with DataFrame: from bokeh.models.widgets import DataTable, TableColumn from bokeh.models import ColumnDataSource data_table = DataTable( columns=[TableColumn(field=Ci, title=Ci) for Ci in df.columns], source=ColumnDataSource(df.head(10)), ) #Create Scatterplot: p_scatter = df.plot_bokeh.scatter( x="petal length (cm)", y="sepal width (cm)", category="species", title="Iris DataSet Visualization", show_figure=False) #Combine Div and Scatterplot via grid layout: pandas_bokeh.plot_grid([[data_table, p_scatter]], plot_width=400, plot_height=350)
def test_pieplot(): "Test Pieplot" p_pie = df_pie = pd.read_csv( os.path.join(test_sets_directory, "Bundestagswahl", "Bundestagswahl.csv") ) p_pie = df_pie.plot_bokeh.pie( x="Partei", y="2017", colormap=["blue", "red", "yellow", "green", "purple", "orange", "grey"], title="Results of German Bundestag Election 2017", show_figure=False, ) p_pie_multiple = df_pie.plot_bokeh( kind="pie", x="Partei", colormap=["blue", "red", "yellow", "green", "purple", "orange", "grey"], title="Results of German Bundestag Elections [2002-2017]", line_color="grey", show_figure=False, ) layout = pandas_bokeh.plot_grid( [[p_pie, p_pie_multiple]], plot_width=450, plot_height=300, show_plot=False ) pandas_bokeh.output_file(os.path.join(directory, "Plots", "Pieplot.html")) pandas_bokeh.save(layout)
def test_pieplot(df_election): "Test Pieplot" p_pie = df_election.plot_bokeh.pie( x="Partei", y="2017", colormap=[ "blue", "red", "yellow", "green", "purple", "orange", "grey" ], title="Results of German Bundestag Election 2017", show_figure=False, ) p_pie_multiple = df_election.plot_bokeh( kind="pie", x="Partei", colormap=[ "blue", "red", "yellow", "green", "purple", "orange", "grey" ], title="Results of German Bundestag Elections [2002-2017]", line_color="grey", show_figure=False, ) p_pie_pandas_backend = df_election.plot.pie( x="Partei", y="2017", colormap=[ "blue", "red", "yellow", "green", "purple", "orange", "grey" ], title="Results of German Bundestag Election 2017", show_figure=False, ) p_pie_multiple_pandas_backend = df_election.plot( kind="pie", x="Partei", colormap=[ "blue", "red", "yellow", "green", "purple", "orange", "grey" ], title="Results of German Bundestag Elections [2002-2017]", line_color="grey", show_figure=False, ) layout = pandas_bokeh.plot_grid( [ [p_pie, p_pie_multiple], [p_pie_pandas_backend, p_pie_multiple_pandas_backend], ], plot_width=450, plot_height=300, show_plot=False, ) pandas_bokeh.output_file(os.path.join(DIRECTORY, "Plots", "Pieplot.html")) pandas_bokeh.save(layout)
def test_area_plots(df_energy): "Test area plots" p_area = df_energy.plot_bokeh.area( x="Year", stacked=True, legend="top_left", colormap=["brown", "orange", "black", "grey", "blue", "green"], title="Worldwide energy consumption split by energy source", ylabel="Million tonnes oil equivalent", ylim=(0, 16000), show_figure=False, ) p_area_normed = df_energy.plot_bokeh( kind="area", x="Year", stacked=True, normed=100, legend="bottom_left", colormap=["brown", "orange", "black", "grey", "blue", "green"], title="Worldwide energy consumption split by energy source", ylabel="Million tonnes oil equivalent", show_figure=False, ) p_area_pandas_backend = df_energy.plot.area( x="Year", stacked=True, legend="top_left", colormap=["brown", "orange", "black", "grey", "blue", "green"], title="Worldwide energy consumption split by energy source", ylabel="Million tonnes oil equivalent", ylim=(0, 16000), show_figure=False, ) p_area_normed_pandas_backend = df_energy.plot( kind="area", x="Year", stacked=True, normed=100, legend="bottom_left", colormap=["brown", "orange", "black", "grey", "blue", "green"], title="Worldwide energy consumption split by energy source", ylabel="Million tonnes oil equivalent", show_figure=False, ) layout = pandas_bokeh.plot_grid([[p_area, p_area_normed]], plot_width=450, plot_height=300, show_plot=False) pandas_bokeh.output_file(os.path.join(DIRECTORY, "Plots", "Areaplot.html")) pandas_bokeh.save(layout)
def plot_Barplot(): plotname = inspect.stack()[0][3][5:] pandas_bokeh.output_file(os.path.join(PLOT_DIR, f"{plotname}.html")) df = df_fruits() df.plot_bokeh.bar(ylabel="Price per Unit [€]", title="Fruit prices per Year", alpha=0.6)
def test_basic_lineplot_rangetool(df_stock): """Test for basic lineplot above with a rangetool extension""" p_basic_lineplot_accessor_pandas_backend = df_stock.plot.line( show_figure=False, rangetool=True) # Output plot as HTML: pandas_bokeh.output_file( os.path.join(DIRECTORY, "Plots", "Basic_lineplot_rangetool.html")) pandas_bokeh.save(p_basic_lineplot_accessor_pandas_backend) assert True
def plot_df_lines_bokeh(df, x_col, y_cols, figures_path, filename, save_flag=False): columns_names = list(df.columns) if save_flag: outfp = os.path.join(figures_path, filename + ".html") output_file(outfp) pandas_bokeh.output_file(outfp) warnings.filterwarnings("ignore") df = df.set_index(x_col, drop=True)[y_cols] df["t"] = df.index.values if x_col == "data" or x_col == "datetime": df.t = df.t.apply(lambda d: str(d.date())) p = df.plot.line(marker="o", plot_data_points=True, panning=True, figsize=(900, 500), legend="top_left", show_figure=False, rangetool=False, hovertool_string=""" t: @t <br/> """) hovers = p.select(dict(type=HoverTool)) flag_first = True for hover in hovers: hover.tooltips = [] if flag_first: for y_col in ["t"] + y_cols: hover.tooltips += [ (y_col, '@{' + y_col + '}'), ] flag_first = False if save_flag: item_text = json.dumps(json_item(p, filename)) output_path = os.path.join(figures_path, filename + ".json") with open(output_path, "w+") as out_f: out_f.write(item_text) save(p) p.background_fill_alpha = 0 p.border_fill_alpha = 0 return p
def plot_rangetool(): plotname = inspect.stack()[0][3][5:] pandas_bokeh.output_file(os.path.join(PLOT_DIR, f"{plotname}.html")) ts = pd.Series(np.random.randn(1000), index=pd.date_range("1/1/2000", periods=1000)) df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, columns=list("ABCD")) df = df.cumsum() df.plot_bokeh(rangetool=True)
def test_histogram(): "Test for histograms" import numpy as np df_hist = pd.DataFrame( { "a": np.random.randn(1000) + 1, "b": np.random.randn(1000), "c": np.random.randn(1000) - 1, }, columns=["a", "b", "c"], ) # Top-on-Top Histogram (Default): p_tt = df_hist.plot_bokeh.hist( bins=np.linspace(-5, 5, 41), vertical_xlabel=True, hovertool=False, title="Normal distributions (Top-on-Top)", line_color="black", show_figure=False, ) # Side-by-Side Histogram (multiple bars share bin side-by-side) also accessible via # kind="hist": p_ss = df_hist.plot_bokeh( kind="hist", bins=np.linspace(-5, 5, 41), histogram_type="sidebyside", vertical_xlabel=True, hovertool=False, title="Normal distributions (Side-by-Side)", line_color="black", show_figure=False, ) # Stacked histogram: p_stack = df_hist.plot_bokeh.hist( bins=np.linspace(-5, 5, 41), histogram_type="stacked", vertical_xlabel=True, hovertool=False, title="Normal distributions (Stacked)", line_color="black", show_figure=False, ) layout = pandas_bokeh.column([p_tt, p_ss, p_stack]) pandas_bokeh.output_file(os.path.join(directory, "Plots", "Histogram.html")) pandas_bokeh.save(layout)
def plot_Stepplot(): plotname = inspect.stack()[0][3][5:] pandas_bokeh.output_file(os.path.join(PLOT_DIR, f"{plotname}.html")) df = df_parabula_cube() plot = df.plot_bokeh.step( x="x", xticks=range(-1, 1), colormap=["#009933", "#ff3399"], title="Pointplot (Parabula vs. Cube)", mode="after", figsize=(800, 300), )
def plot_Pointplot(): plotname = inspect.stack()[0][3][5:] pandas_bokeh.output_file(os.path.join(PLOT_DIR, f"{plotname}.html")) df = df_parabula_cube() plot = df.plot_bokeh.point( x="x", xticks=range(-3, 4), size=5, colormap=["#009933", "#ff3399"], title="Pointplot (Parabula vs. Cube)", marker="x", )
def plot_lines_dashboard_ita(cases_df, figures_path, geo_name, plot_dashboard_flag): for save_flag in [False]: p1 = plot_df_lines_bokeh(cases_df, "data", [ "totale_tamponi", "totale_casi", ], figures_path, "tamponi", save_flag) p2 = plot_df_lines_bokeh(cases_df, "data", [ "totale_attualmente_positivi", "totale_deceduti", "totale_dimessi_guariti" ], figures_path, "totali_principali", save_flag) p3 = plot_df_lines_bokeh(cases_df, "data", [ "nuovi_positivi", "nuovi_attualmente_positivi", "nuovi_deceduti", "nuovi_dimessi_guariti" ], figures_path, "nuovi_principali", save_flag) p4 = plot_df_lines_bokeh(cases_df, "data", [ "tasso_positivi_tamponi", "tasso_nuovi_positivi", "tasso_mortalita", "tasso_guarigione" ], figures_path, "tassi_principali", save_flag) p5 = plot_df_lines_bokeh(cases_df, "data", [ "attualmente_isolamento_domiciliare", "attualmente_ricoverati", "attualmente_terapia_intensiva", ], figures_path, "dettaglio_pazienti_attuali", save_flag) p6 = plot_df_lines_bokeh(cases_df, "data", [ "tasso_ricoverati_con_sintomi", "tasso_terapia_intensiva", "tasso_terapia_intensiva_ricoverati", ], figures_path, "tassi_condizioni_cliniche", save_flag) if plot_dashboard_flag: outfp = os.path.join(figures_path, geo_name + ".html") output_file(outfp) pandas_bokeh.output_file(outfp) plot_grid = pandas_bokeh.plot_grid([ [p1, p2], [p3, p4], [p5, p6], ], toolbar_location="left") # pandas_bokeh.save(plot_grid) save(plot_grid)
def plot_Barplot3(): plotname = inspect.stack()[0][3][5:] pandas_bokeh.output_file(os.path.join(PLOT_DIR, f"{plotname}.html")) df = df_fruits() p_bar = df.plot_bokeh.bar( ylabel="Price per Unit [€]", title="Fruit prices per Year", alpha=0.6, show_figure=False, ) p_stacked_bar = df.plot_bokeh.bar( ylabel="Price per Unit [€]", title="Fruit prices per Year", stacked=True, alpha=0.6, show_figure=False, ) # Reset index, such that "fruits" is now a column of the DataFrame: df.reset_index(inplace=True) # Create horizontal bar (via kind keyword): p_hbar = df.plot_bokeh( kind="barh", x="fruits", xlabel="Price per Unit [€]", title="Fruit prices per Year", alpha=0.6, legend="bottom_right", show_figure=False, ) # Create stacked horizontal bar (via barh accessor): p_stacked_hbar = df.plot_bokeh.barh( x="fruits", stacked=True, xlabel="Price per Unit [€]", title="Fruit prices per Year", alpha=0.6, legend="bottom_right", show_figure=False, ) pandas_bokeh.plot_grid([[p_bar, p_stacked_bar], [p_hbar, p_stacked_hbar]], plot_width=450)
def test_histogram_average_diplay(df_hist): "Test average & cumulative function of histogram" p_hist = df_hist.plot_bokeh.hist( y=["a", "b"], bins=np.arange(-4, 6.5, 0.5), normed=100, vertical_xlabel=True, ylabel="Share[%]", title="Normal distributions (normed)", show_average=True, xlim=(-4, 6), ylim=(0, 30), show_figure=False, ) p_hist_cum = df_hist.plot_bokeh.hist( y=["a", "b"], bins=np.arange(-4, 6.5, 0.5), normed=100, cumulative=True, vertical_xlabel=True, ylabel="Share[%]", title="Normal distributions (normed & cumulative)", show_figure=False, ) p_hist_cum_pandas_backend = df_hist.plot.hist( by=["a", "b"], bins=np.arange(-4, 6.5, 0.5), normed=100, cumulative=True, vertical_xlabel=True, ylabel="Share[%]", title="Normal distributions (normed & cumulative)", show_figure=False, ) p_average = pandas_bokeh.plot_grid( [[p_hist, p_hist_cum, p_hist_cum_pandas_backend]], plot_width=450, plot_height=300, show_plot=False, ) pandas_bokeh.output_file( os.path.join(DIRECTORY, "Plots", "Histogram_average_and_cumulative.html")) pandas_bokeh.save(p_average)
def test_autosizing(df_fruits): """ Autoscaling test """ kwargs = dict(figsize=(500, 200), sizing_mode="scale_width", show_figure=False) p_autoscale = df_fruits.plot_bokeh(kind="bar", **kwargs) pandas_bokeh.output_file(os.path.join(DIRECTORY, "Plots", "AutoScale.html")) pandas_bokeh.save(p_autoscale) assert True
def totals_plot(self, countries=None): total_df = self.calc_totals(countries) total_df['currently_sick'] = (total_df.confirmed - total_df.deaths - total_df.recovered) total_df = total_df.drop('confirmed', axis=1) c_string = self.countries_to_string(countries) pandas_bokeh.output_file(os.path.join('figures', 'totals.html')) curdoc().theme = Theme(json=jt) total_df.plot_bokeh.area( figsize=(1500, 750), title=f'Total COVID-19 numbers, {c_string}' + self.data_disclaimer, ylabel='Number of individuals affected (stacked)', stacked=True, sizing_mode='scale_both')
def plot_comparison_df_bokeh(df, y_cols, figures_path, filename, save_flag=False): columns_names = list(df.columns) if save_flag: outfp = os.path.join(figures_path, filename + ".html") output_file(outfp) pandas_bokeh.output_file(outfp) warnings.filterwarnings("ignore") df.index.name = "t" p = df.plot.line(marker="o", plot_data_points=True, panning=True, figsize=(1200, 600), legend="top_left", show_figure=False, rangetool=False, hovertool_string=""" t: @t <br/> """) hovers = p.select(dict(type=HoverTool)) flag_first = True for hover in hovers: hover.tooltips = [] if flag_first: for y_col in df.columns: hover.tooltips += [ (y_col, '@{' + y_col + '}'), ] flag_first = False if save_flag: item_text = json.dumps(json_item(p, filename)) output_path = os.path.join(figures_path, filename + ".json") with open(output_path, "w+") as out_f: out_f.write(item_text) save(p) return p
def test_histogram_average_diplay(): "Test average & cumulative function of histogram" import numpy as np df_hist = pd.DataFrame( { "a": np.random.randn(1000) + 1, "b": np.random.randn(1000), "c": np.random.randn(1000) - 1, }, columns=["a", "b", "c"], ) p_hist = df_hist.plot_bokeh.hist( y=["a", "b"], bins=np.arange(-4, 6.5, 0.5), normed=100, vertical_xlabel=True, ylabel="Share[%]", title="Normal distributions (normed)", show_average=True, xlim=(-4, 6), ylim=(0, 30), show_figure=False, ) p_hist_cum = df_hist.plot_bokeh.hist( y=["a", "b"], bins=np.arange(-4, 6.5, 0.5), normed=100, cumulative=True, vertical_xlabel=True, ylabel="Share[%]", title="Normal distributions (normed & cumulative)", show_figure=False, ) p_average = pandas_bokeh.plot_grid( [[p_hist, p_hist_cum]], plot_width=450, plot_height=300, show_plot=False ) pandas_bokeh.output_file( os.path.join(directory, "Plots", "Histogram_average_and_cumulative.html") ) pandas_bokeh.save(p_average)
def plot_Scatterplot2(): plotname = inspect.stack()[0][3][5:] pandas_bokeh.output_file(os.path.join(PLOT_DIR, f"{plotname}.html")) df = df_iris() df = df.sample(frac=1) #Change one value to clearly see the effect of the size keyword df.loc[13, "sepal length (cm)"] = 15 #Make scatterplot: p_scatter = df.plot_bokeh.scatter( x="petal length (cm)", y="sepal width (cm)", category="species", title="Iris DataSet Visualization with Size Keyword", size="sepal length (cm)")
def draw_graph(df, key_selected): plots = [] result_type_name = key_selected.replace("_", " ").capitalize() for alg in set(sorted(df[k0_algorithm].values)): alg_name = alg alg_type = "scheduling" if "heuristic" in alg: alg_name = "OGSA" elif "optimal" in alg: alg_name = "Optimisation model" if "fw" in alg: alg_name += " with FW" alg_type = "pricing" df_selected = df.loc[lambda df2: df[k0_algorithm] == alg, lambda df2: [k0_households_no, key_selected]] df_selected = df_selected.set_index(k0_households_no) y_label = "" if "time" in key_selected: y_label = "Run time (seconds)" elif "iteration" in key_selected: y_label = "Iteration" elif "reduction" in key_selected: y_label = key_selected.replace("_", " ").capitalize() p_line = df_selected.plot_bokeh( kind="line", title="{} of {}, {}".format(result_type_name, alg_type, alg_name), xlabel="Number of Households", ylabel=y_label, show_figure=False, sizing_mode="scale_width", ) if "reduction" in key_selected: p_line.yaxis.formatter = NumeralTickFormatter(format='0 %') p_line.legend.location = "top_left" p_line.y_range.start = 0 plots.append(p_line) pandas_bokeh.output_file("{}{}.html".format(dt_folder, result_type_name)) grid = pandas_bokeh.plot_grid(plots, ncols=2, show_plot=False) pandas_bokeh.save(grid)
def plot_ApplevsGoogle_3(): plotname = inspect.stack()[0][3][5:] pandas_bokeh.output_file(os.path.join(PLOT_DIR, f"{plotname}.html")) df = df_stocks() plot = df.plot_bokeh( figsize=(800, 450), title="Apple vs Google", xlabel="Date", ylabel="Stock price [$]", yticks=[0, 100, 200, 300, 400], ylim=(100, 200), xlim=("2001-01-01", "2001-02-01"), colormap=["red", "blue"], plot_data_points=True, plot_data_points_size=10, marker="asterisk", )
def simple_plot(self, countries=['Germany', 'Austria', 'Italy']): if type(countries) != list: raise TypeError('countries argument accepts type list, ' f'got {type(countries)} instead') confirmed = self.confirmed_df.loc[:, (countries, slice(None), slice(None), slice(None))] confirmed.columns = ( confirmed.columns.droplevel(3).droplevel(2).droplevel(1)) pandas_bokeh.output_file(os.path.join('figures', 'simple_plot.html')) curdoc().theme = Theme(json=jt) confirmed.plot_bokeh.line(figsize=(1500, 750), title="simple plot", plot_data_points=True, plot_data_points_size=5, marker="circle", sizing_mode='scale_both')
def lineplot(x: str, y: list, data, title="Line Plot", output_file="", **lineplot_kwargs): """ Plots a line plot. Parameters ---------- x : str X axis column y : list Y axis column data : Dataframe Dataframe title : str, optional Title of the plot, by default 'Line Plot' output_file : str, optional If a name is provided save the plot to an html file, by default '' """ y.append(x) data_copy = data[y].copy() data_copy = data_copy.set_index(x) xlabel = lineplot_kwargs.pop("xlabel", x) p_line = data_copy.plot_bokeh.line(title=title, xlabel=xlabel, **lineplot_kwargs) if output_file: # pragma: no cover if Path(output_file).suffix == ".html": pandas_bokeh.output_file(os.path.join(IMAGE_DIR, output_file)) else: export_png(p_line, os.path.join(IMAGE_DIR, output_file))
def plot_Histogram(): plotname = inspect.stack()[0][3][5:] pandas_bokeh.output_file(os.path.join(PLOT_DIR, f"{plotname}.html")) df = df_hist() # Top-on-Top Histogram (Default): p1 = df.plot_bokeh.hist( bins=np.linspace(-5, 5, 41), vertical_xlabel=True, hovertool=False, title="Normal distributions (Top-on-Top)", line_color="black", show_figure=False, ) # Side-by-Side Histogram (multiple bars share bin side-by-side) also accessible via # kind="hist": p2 = df.plot_bokeh( kind="hist", bins=np.linspace(-5, 5, 41), histogram_type="sidebyside", vertical_xlabel=True, hovertool=False, title="Normal distributions (Side-by-Side)", line_color="black", show_figure=False, ) # Stacked histogram: p3 = df.plot_bokeh.hist( bins=np.linspace(-5, 5, 41), histogram_type="stacked", vertical_xlabel=True, hovertool=False, title="Normal distributions (Stacked)", line_color="black", show_figure=False, ) pandas_bokeh.plot_grid([[p1], [p2], [p3]])
def plot_ApplevsGoogle_2(): plotname = inspect.stack()[0][3][5:] pandas_bokeh.output_file(os.path.join(PLOT_DIR, f"{plotname}.html")) df = df_stocks() plot = df.plot_bokeh( figsize=(800, 450), y="Apple", title="Apple vs Google", xlabel="Date", ylabel="Stock price [$]", yticks=[0, 100, 200, 300, 400], ylim=(0, 400), toolbar_location=None, colormap=["red", "blue"], hovertool_string=r"<img src='https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Apple_logo_black.svg/170px-Apple_logo_black.svg.png' height='42' alt='@imgs' width='42' style='float: left; margin: 0px 15px 15px 0px;' border='2' ></img> Apple \n\n<h4> Stock Price: </h4> @{Apple}", panning=False, zooming=False, )
def test_mapplot(): "Mapplot test" df_mapplot = pd.read_csv(os.path.join(test_sets_directory, "populated places","populated_places.csv")) df_mapplot["size"] = df_mapplot["pop_max"] / 1000000 p_map = df_mapplot.plot_bokeh.map( x="longitude", y="latitude", hovertool_string="""<h2> @{name} </h2> <h3> Population: @{pop_max} </h3>""", tile_provider="STAMEN_TERRAIN_RETINA", size="size", figsize=(900, 600), title="World cities with more than 1.000.000 inhabitants", show_figure=False) pandas_bokeh.output_file(os.path.join(directory, "Plots", "Mapplot.html")) pandas_bokeh.save(p_map)
def lineplot(x: str, y: list, data, title="Line Plot", output_file="", **lineplot_kwargs): """ Plots a line plot. Parameters ---------- x : str X axis column y : list Y axis column data : Dataframe Dataframe title : str, optional Title of the plot, by default 'Line Plot' output_file : str, optional If a name is provided save the plot to an html file, by default '' """ data_copy = data[[x] + y].copy() data_copy = data_copy.set_index(x) xlabel = lineplot_kwargs.pop("xlabel", x) p_line = data_copy.plot_bokeh.line(title=title, xlabel=xlabel, **lineplot_kwargs) if output_file: pandas_bokeh.output_file(output_file) pandas_bokeh.save(p_line)
def plot_lines_dashboard(cases_df, figures_path, geo_name, plot_dashboard_flag): if plot_dashboard_flag: save_flag = False outfp = os.path.join(figures_path, geo_name + ".html") output_file(outfp) pandas_bokeh.output_file(outfp) else: save_flag = True p1 = plot_df_lines_bokeh(cases_df, "datetime", [ "total_cases", ], figures_path, "cases", save_flag) p2 = plot_df_lines_bokeh(cases_df, "datetime", ["total_deaths", "total_recovered"], figures_path, "main_totals", save_flag) p3 = plot_df_lines_bokeh(cases_df, "datetime", [ "new_positives", "new_currently_positives", "new_deaths", "new_recovered" ], figures_path, "main_new", save_flag) p4 = plot_df_lines_bokeh( cases_df, "datetime", ["rate_new_positives", "rate_deaths", "rate_recovered"], figures_path, "main_rate", save_flag) if plot_dashboard_flag: plot_grid = pandas_bokeh.plot_grid([ [p1, p2], [p3, p4], ], toolbar_location="left") # pandas_bokeh.save(plot_grid) save(plot_grid)