Package: apolitical-data-viz
apolitical-data-vizThis module defines the Apolitical (https://apolitical.co) 'house style' for data visualisation and provides various tools for plotting data. It is intended to be compatible with Google Colab.We build heavily upon the foundations ofmatplotliband utilities provided byseaborn, and aim for compatibility withpandas.InstallationTo install from the command line viapip, do:pip install apolitical-data-vizTo upgrade to the latest version viapipdo:pip install apolitical-data-viz --upgradeTo use viapipenvput the following in your Pipfile:[packages]
apolitical-data-viz = ">=1.0.0"DevelopmentIf you've cloned the repository, the best way to make it work is usingpipenvIf you don't yet havepipenv, you can usepipto install it from the command line:pip install pipenv --upgradeThen, in the top level directory of this repository,apolitical-data-viz, do:pipenv install --devThis will create the virtual environment and install the requirements (viewable in the Pipfile). The--devflag will install packages needed for testing etc.UsageTo import the module, do the following:import apol_datavizor e.g.import apol_dataviz as advThis provides a variety of resources (they can also be imported separately, as demonstrated in the next example).Applying the house styleThe simplest usage is to simply enforce the house style. In order to do this, do the following:from apol_dataviz import style
style.use_apol_style()This will create a number of new matplotlib colour aliases as well as some new named colourmaps. Note that if you are using Google Colab, we anticipate that the Lato font will be missing and so we download the relevant.ttffiles. This functionality relies on a check thatgoogle-colabis in thesys.moduleslist. If it is not, nothing is downloaded (you should ensure the Lato font is installed in your local<PATH>/matplotlib/mpl-data/fonts/ttf/directory in this case, else matplotlib will fall back on the default font).Accessing the colour definitionsIf you don't want to enforce the full style, but do want to access our colour definitions, do the following:from apol_dataviz.colours import ColourDefinitions

cd = ColourDefinitions()

cd.apply_definitions() # this command sets up the matplotlib aliasesTheColourDefinitionsclass contains the definitions of a wide variety of colours used in our visualisations. Itsapply_definitions()method sets up the aliases for these in matplotlib.Using the custom plot utilitiesWe provide a number of different functions for plotting custom charts. These are accessible via theplotsresource. These are intended to be compatible with pandas Series and DataFramesfrom apol_dataviz.plots import doughnut, hbarplot

axis = doughnut(pandas_series)
axis = hbarplot(pandas_series)The above commands would make nicely formatted doughnut (donut) plots and horizontal bar plots respectively.Formatting plotsIn many cases we may want to format a plot in a particular way, and for this purpose we provide formatters that either alter the formatting of a particular plot or act as a utility for doing so.As an example:from apol_dataviz import formatters

new_tick_labels = formatters.get_ts_tick_labels(pandas_timeseries)This creates well-formatted tick labels for a datetime-indexed pandas time series.Using the palette generatorsWe make available a number of functions for generating palettes of specific types.To give a couple of examples:from apol_dataviz import palette_generators as palgen

easy_sequential = palgen.apol_teal_pal()

categorical_via_HuSL = palgen.spaced_hue_palette()