def separate_legend(fig: Figure, orientation: str = "vertical") -> Figure: """Cuts legend out of fig and returns a separate legend (as a Figure object). Click policy doesn't work on the new legend. Requires bokeh==1.0.2 for solution from https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/BJRhWlnmhWU Open feature request to share a legend across plots: https://github.com/bokeh/bokeh/issues/7607 """ legend_fig = Plot( x_range=Range1d(1000, 1000), y_range=Range1d(1000, 1000), min_border=0, outline_line_alpha=0, toolbar_location=None, sizing_mode= "stretch_both", # if stretch_both, then we need to set the height or min-height of the container ) original_legend = fig.legend[0] legend_fig.renderers.append(original_legend) legend_fig.renderers.extend([ renderer for renderer in fig.renderers if isinstance(renderer, GlyphRenderer) ]) fig.renderers.remove(original_legend) separated_legend = legend_fig.legend[0] separated_legend.border_line_alpha = 0 separated_legend.margin = 0 if len(separated_legend.items) > 3: orientation = "vertical" separated_legend.orientation = orientation if orientation == "horizontal": separated_legend.spacing = 30 separated_legend.location = "top_center" legend_fig.plot_height = (compute_legend_height(original_legend) + original_legend.margin * 2) return legend_fig
plot_O3.xaxis.axis_label = 'utc_time' plot_CO.xaxis.axis_label = 'utc_time' plot_grid.xaxis.axis_label = 'latitude' plot_grid_station.xaxis.axis_label = 'latitude' plot_O3.yaxis.axis_label = 'O3' plot_CO.yaxis.axis_label = 'CO' plot_grid.yaxis.axis_label = 'longitude' plot_grid_station.yaxis.axis_label = 'longitude' plot_O3.plot_width = 1500 plot_CO.plot_width = 1500 plot_grid.plot_width = 900 plot_grid_station.plot_width = 900 plot_grid.plot_height = 900 plot_grid_station.plot_height = 900 ###------------------------------------------------------------------------------- # plots 1 (O3) and 2 (CO) ###------------------------------------------------------------------------------- listStationId = data_beijing_17_18_aq["stationId"].unique() listWithStation = {} i = 0 result = pd.DataFrame() #create dataframe with column for each critere "O3, stationId .." and for each stationId and we have less row because it's easy for the plot for idOfStation in listStationId: listWithStation[i] = data_beijing_17_18_aq.loc[ lambda df: df['stationId'] == listStationId[i], :][[