Last active
March 19, 2023 15:54
-
-
Save Joyakis/016ce91cafdb248e3fbbae7ec5ce065d to your computer and use it in GitHub Desktop.
I updated one of bokeh's plots using the following code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' A grouped bar chart using a cleaned up version of the `Auto MPG dataset`_. | |
This examples demonstrates automatic handing of Pandas GroupBy objects and | |
colormapping nested factors with ``factor_cmap``. A hover tooltip displays | |
information for each bar. | |
.. bokeh-example-metadata:: | |
:sampledata: autompg | |
:apis: bokeh.plotting.figure.vbar, bokeh.transform.factor_cmap | |
:refs: :ref:`ug_basic_bars_pandas` | |
:keywords: bars, categorical, colormap, groupby, pandas | |
.. _Auto MPG dataset: https://archive.ics.uci.edu/ml/datasets/auto+mpg | |
''' | |
#from bokeh.palettes import Cividis5 | |
from bokeh.plotting import figure, show | |
from bokeh.sampledata.autompg import autompg_clean as df | |
from bokeh.transform import factor_cmap | |
from math import pi | |
df.cyl = df.cyl.astype(str) | |
df.yr = df.yr.astype(str) | |
group = df.groupby(['cyl', 'mfr']) | |
index_cmap = factor_cmap('cyl_mfr', palette=Cividis5, factors=sorted(df.cyl.unique()), end=1) | |
p = figure(width=800, height=300, title="Mean MPG by # Cylinders and Manufacturer", | |
x_range=group, toolbar_location=None, tooltips=[("MPG", "@mpg_mean"), ("Cyl, Mfr", "@cyl_mfr")]) | |
p.vbar(x='cyl_mfr', top='mpg_mean', width=1, source=group, | |
line_color="white", fill_color=index_cmap, ) | |
p.y_range.start = 0 | |
p.x_range.range_padding = 0.05 | |
p.xgrid.grid_line_color = None | |
p.xaxis.axis_label = "Manufacturer grouped by # Cylinders" | |
p.xaxis.major_label_orientation = pi/2 # set x-axis tick labels to be at 45 degrees | |
p.xaxis.axis_label_text_font_size = "16pt" | |
p.yaxis.axis_label = "Mean MPG" #Adding y axis label | |
p.outline_line_color = None | |
show(p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On the code above i used the Cividis5 palette instead because of its accesibiity. The cividis5 palette was specifically designed to be accessible to people with color vision deficiencies, such as those with red-green color blindness. It has been tested and found to be effective for all types of color vision, making it a more inclusive choice for data visualization.I also included the y_axis label and named it "mean mpg" for easy understanding of the plot.Finally i changed the position of the xtick labels for easy readability