Source code for nowcast.figures.website_theme

# Copyright 2016-2019 Doug Latornell, 43ravens
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Colour, fonts, and utility functions that define the look and style of figures for the
https://gomss.ocean.dal.ca/ web pages.
"""

from matplotlib.font_manager import FontProperties

#: The :kbd:`salishsea.eos.ubc.ca/nemo/` pages background colour,
#: from the https://bootswatch.com/superhero/ theme.
SITE_BACKGROUND_COLOUR = "white"

#: Colours of various figure elements;
#: the dict key(s) should be descriptive enough to identify the element
#: to which the colour applies.
COLOURS = {
    "axes": {"facecolor": "#dbdee1"},
    "axis": {"labels": "black", "spines": "black", "ticks": "black"},
    "cbar": {"label": "black", "tick labels": "black"},
    "contour lines": {"1000m isobath": "white"},
    "figure": {"facecolor": SITE_BACKGROUND_COLOUR},
    "land": "#8b7765",
    "coastline": "black",
    "text": {"axis": "black", "figure title": "black"},
}

#: Font properties of various figure text elements;
#: the top level dict keys should be descriptive enough to identify the element
#: to which the font properties apply.
FONTS = {
    "axis": FontProperties(
        family=["Bitstream Vera Sans", "sans-serif"], weight="medium", size=15
    ),
    "axis small": FontProperties(
        family=["Bitstream Vera Sans", "sans-serif"], weight="medium", size=12
    ),
    "cbar": {
        "label": FontProperties(
            family=["Bitstream Vera Sans", "sans-serif"], weight="medium", size=15
        ),
        "tick labels": FontProperties(
            family=["Bitstream Vera Sans", "sans-serif"], weight="medium", size=12
        ),
    },
    "figure title": FontProperties(
        family=["Bitstream Vera Sans", "sans-serif"], weight="medium", size=15
    ),
}


[docs]def set_axis_colors(ax): """Set the colours of axis labels, ticks, and spines. :arg ax: Axes object to be formatted. :type ax: :py:class:`matplotlib.axes.Axes` """ ax.set_facecolor(COLOURS["axes"]["facecolor"]) ax.xaxis.label.set_color(COLOURS["axis"]["labels"]) ax.yaxis.label.set_color(COLOURS["axis"]["labels"]) ax.tick_params(axis="x", colors=COLOURS["axis"]["ticks"]) ax.tick_params(axis="y", colors=COLOURS["axis"]["ticks"]) ax.spines["bottom"].set_color(COLOURS["axis"]["spines"]) ax.spines["top"].set_color(COLOURS["axis"]["spines"]) ax.spines["left"].set_color(COLOURS["axis"]["spines"]) ax.spines["right"].set_color(COLOURS["axis"]["spines"])