Skip to content

Commit

Permalink
Merge pull request #87 from lukelbd/fonts-cleanup
Browse files Browse the repository at this point in the history
Stop syncing fonts
  • Loading branch information
lukelbd committed Dec 16, 2019
2 parents 79dc6d6 + f8cf9a3 commit ddbc23f
Show file tree
Hide file tree
Showing 91 changed files with 220 additions and 189 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.rst
Expand Up @@ -60,14 +60,15 @@ ProPlot v0.3.0 (2020-01-##)
with a default ``.proplotrc`` file, change the auto-generated user ``.proplotrc``
(:pr:`50`).

ProPlot v0.2.8 (2019-12-##)
ProPlot v0.2.8 (2019-12-15)
===========================
.. rubric:: Deprecated

- Remove ``'Moisture'`` colormap (:commit:`cf8952b1`).

.. rubric:: Features

- Add `~proplot.styletools.use_font`, only sync Google Fonts fonts (:pr:`87`).
- New ``'DryWet'`` colormap is colorblind friendly (:commit:`0280e266`).
- Permit shifting arbitrary colormaps by ``180`` degrees by appending the
name with ``'_shifted'``, just like ``'_r'`` (:commit:`e2e2b2c7`).
Expand All @@ -84,6 +85,10 @@ ProPlot v0.2.8 (2019-12-##)

- Cleanup notebooks, especially the colormaps demo (e.g. :commit:`952d4cb3`).

.. rubric:: Internals

- Change `~time.clock` to `~time.perf_counter` (:pr:`86`).

ProPlot v0.2.7 (2019-12-09)
===========================

Expand Down
10 changes: 5 additions & 5 deletions docs/colors_fonts.ipynb
Expand Up @@ -41,14 +41,14 @@
"outputs": [],
"source": [
"import proplot as plot\n",
"f = plot.show_colors()"
"figs = plot.show_colors()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Sampling colormaps and cycles"
"## Drawing from cmaps and cycles"
]
},
{
Expand All @@ -57,7 +57,7 @@
"raw_mimetype": "text/restructuredtext"
},
"source": [
"If you want to draw an individual color from a smooth colormap or a color cycle, use ``color=(cmap, coord)`` or ``color=(cycle, index)`` with any command that accepts the `color` keyword. The `coord` should be between ``0`` and ``1``, while the `index` is the index on the list of cycle colors. This feature is powered by the `~proplot.styletools.ColorDict` class."
"If you want to draw an individual color from a smooth colormap or a color cycle, use ``color=(cmap, coord)`` or ``color=(cycle, index)`` with any command that accepts the `color` keyword. The ``coord`` should be between ``0`` and ``1``, while the ``index`` is the index on the list of cycle colors. This feature is powered by the `~proplot.styletools.ColorDict` class. This is useful if you spot a nice color in one of the available colormaps and want to use it for some arbitrary plot element."
]
},
{
Expand Down Expand Up @@ -106,7 +106,7 @@
"raw_mimetype": "text/restructuredtext"
},
"source": [
"DejaVu Sans is the default matplotlib font, but it's not very aesthetically pleasing. ProPlot adds a bunch of sans-serif fonts so that you have them on every workstation, introduces a `~proplot.styletools.show_fonts` command to display them (see below), and makes Helvetica the default, as in MATLAB. Generally speaking, simple, clean sans-serif fonts are more appropriate for figures than serif fonts.\n",
"DejaVu Sans is the default matplotlib font, but it's not very aesthetically pleasing. ProPlot adds a few sans-serif fonts, introduces a `~proplot.styletools.show_fonts` command to display the available sans-serif fonts on your system, and tries to make the default font. Generally speaking, simple, clean sans-serif fonts are more appropriate for figures than serif fonts.\n",
"\n",
"You can register your own fonts by adding ``.ttf`` and ``.otf`` files to the ``~/.proplot/fonts`` directory and calling `~proplot.styletools.register_fonts` (which is also called on import). To change the default font, use the `~proplot.rctools.rc` object or modify your ``~/.proplotrc``. See :ref:`Configuring proplot` for details."
]
Expand All @@ -118,7 +118,7 @@
"outputs": [],
"source": [
"import proplot as plot\n",
"plot.rc.reset()\n",
"import matplotlib.font_manager as mfonts\n",
"f = plot.show_fonts()"
]
}
Expand Down
32 changes: 25 additions & 7 deletions docs/why.rst
Expand Up @@ -449,20 +449,38 @@ to *points* -- for example, :rcraw:`linewidth`, :rcraw:`ticklen`,
:rcraw:`axes.titlesize`, and :rcraw:`axes.titlepad`.
See :ref:`Configuring proplot` for details.

Working with fonts
==================

The .proplot folder
===================
.. rubric:: Problem

In matplotlib, the default font is DejaVu Sans. In this developer's humble opinion, DejaVu Sans is fugly AF. It is also really tricky to add custom fonts to matplotlib.
In matplotlib, it can be difficult to design your
own colormaps and color cycles, and there is no builtin
way to *save* them for future use. It is also quite
difficult to get matplotlib to use custom ``.ttc``, ``.ttf``,
and ``.otf`` font files, which may be desirable when you are
working on Linux servers with limited font selections.

..
This font is not very aesthetically pleasing.

.. rubric:: Solution

ProPlot comes packaged with several additional fonts. The new default font is Helvetica; albeit somewhat overused, this is a tried and tested, aesthetically pleasing sans serif font.
ProPlot automatically adds colormaps, color cycles, and font files
saved in the ``.proplot/cmaps``, ``.proplot/cycles``, and ``.proplot/fonts``
folders in your home directory.
You can save colormaps and color
cycles to these folders simply by passing ``save=True`` to
`~proplot.styletools.Colormap` and `~proplot.styletools.Cycle`.
To *manually* load from these folders, e.g. if you have added
files to these folders but you do not want to restart your
ipython session, simply call
`~proplot.styletools.regsiter_cmaps`,
`~proplot.styletools.regsiter_cycles`, and
`~proplot.styletools.regsiter_fonts`.

Matplotlib adds font files from paths listed in the ``$TTFPATH`` environment variable (surprisingly, this feature is undocumented!), so ProPlot populates this variable. This also permits using *your own* font files by dropping them in the ``~/.proplot/fonts`` folder.
..
As mentioned above,
ProPlot introduces the `~proplot.styletools.Colormap` and `~proplot.styletools.Cycle`.
functions for designing your own colormaps and color cycles.
..
...and much more!
Expand Down
3 changes: 1 addition & 2 deletions proplot/.proplotrc
Expand Up @@ -12,7 +12,7 @@ coast: False
color: k
cycle: colorblind
facecolor: w
fontname: 'Helvetica Neue'
fontname: auto
geogrid: True
grid: True
gridminor: False
Expand Down Expand Up @@ -151,7 +151,6 @@ legend.fancybox: False
legend.handletextpad: 0.5
lines.linewidth: 1.3
lines.markersize: 3.0
mathtext.default: regular
savefig.bbox: standard
savefig.directory:
savefig.dpi: 300
Expand Down
16 changes: 8 additions & 8 deletions proplot/__init__.py
Expand Up @@ -5,22 +5,22 @@
import os as _os
import pkg_resources as _pkg
from .utils import _benchmark
from .utils import * # noqa: F401 F403
with _benchmark('total time'):
from .utils import * # noqa
with _benchmark('styletools'):
from .styletools import * # noqa
from .styletools import * # noqa: F401 F403
with _benchmark('rctools'):
from .rctools import * # noqa
from .rctools import * # noqa: F401 F403
with _benchmark('axistools'):
from .axistools import * # noqa
from .axistools import * # noqa: F401 F403
with _benchmark('wrappers'):
from .wrappers import * # noqa
from .wrappers import * # noqa: F401 F403
with _benchmark('projs'):
from .projs import * # noqa
from .projs import * # noqa: F401 F403
with _benchmark('axes'):
from .axes import * # noqa
from .axes import * # noqa: F401 F403
with _benchmark('subplots'):
from .subplots import * # noqa
from .subplots import * # noqa: F401 F403


# Initialize customization folders
Expand Down
Binary file removed proplot/fonts/Arial Bold Italic.ttf
Binary file not shown.
Binary file removed proplot/fonts/Arial Bold.ttf
Binary file not shown.
Binary file removed proplot/fonts/Arial Italic.ttf
Binary file not shown.
Binary file removed proplot/fonts/Arial.ttf
Binary file not shown.
Binary file removed proplot/fonts/Avenir.ttc
Binary file not shown.
Binary file removed proplot/fonts/Avenir_0.ttf
Binary file not shown.
Binary file removed proplot/fonts/Avenir_1.ttf
Binary file not shown.
Binary file removed proplot/fonts/Avenir_10.ttf
Binary file not shown.
Binary file removed proplot/fonts/Avenir_11.ttf
Binary file not shown.
Binary file removed proplot/fonts/Avenir_2.ttf
Binary file not shown.
Binary file removed proplot/fonts/Avenir_3.ttf
Binary file not shown.
Binary file removed proplot/fonts/Avenir_4.ttf
Binary file not shown.
Binary file removed proplot/fonts/Avenir_5.ttf
Binary file not shown.
Binary file removed proplot/fonts/Avenir_6.ttf
Binary file not shown.
Binary file removed proplot/fonts/Avenir_7.ttf
Binary file not shown.
Binary file removed proplot/fonts/Avenir_8.ttf
Binary file not shown.
Binary file removed proplot/fonts/Avenir_9.ttf
Binary file not shown.
Binary file removed proplot/fonts/Franklin Gothic Book Italic.ttf
Binary file not shown.
Binary file removed proplot/fonts/Franklin Gothic Book.ttf
Binary file not shown.
Binary file removed proplot/fonts/Franklin Gothic Medium Italic.ttf
Binary file not shown.
Binary file removed proplot/fonts/Franklin Gothic Medium.ttf
Binary file not shown.
Binary file removed proplot/fonts/Frutiger.ttf
Binary file not shown.
Binary file removed proplot/fonts/Frutiger_bold.ttf
Binary file not shown.
Binary file removed proplot/fonts/Futura.ttc
Binary file not shown.
Binary file removed proplot/fonts/Futura_0.ttf
Binary file not shown.
Binary file removed proplot/fonts/Futura_1.ttf
Binary file not shown.
Binary file removed proplot/fonts/Futura_2.ttf
Binary file not shown.
Binary file removed proplot/fonts/Futura_3.ttf
Binary file not shown.
Binary file removed proplot/fonts/Futura_4.ttf
Binary file not shown.
Binary file removed proplot/fonts/Geneva.ttf
Binary file not shown.
Binary file removed proplot/fonts/GillSans.ttc
Binary file not shown.
Binary file removed proplot/fonts/GillSans_0.ttf
Binary file not shown.
Binary file removed proplot/fonts/GillSans_1.ttf
Binary file not shown.
Binary file removed proplot/fonts/GillSans_2.ttf
Binary file not shown.
Binary file removed proplot/fonts/GillSans_3.ttf
Binary file not shown.
Binary file removed proplot/fonts/GillSans_4.ttf
Binary file not shown.
Binary file removed proplot/fonts/GillSans_5.ttf
Binary file not shown.
Binary file removed proplot/fonts/GillSans_6.ttf
Binary file not shown.
Binary file removed proplot/fonts/GillSans_7.ttf
Binary file not shown.
Binary file removed proplot/fonts/GillSans_8.ttf
Binary file not shown.
Binary file removed proplot/fonts/Helvetica.ttf
Binary file not shown.
Binary file removed proplot/fonts/HelveticaBold.ttf
Binary file not shown.
Binary file removed proplot/fonts/HelveticaBoldOblique.ttf
Binary file not shown.
Binary file removed proplot/fonts/HelveticaNeue.ttf
Binary file not shown.
Binary file removed proplot/fonts/HelveticaNeueBold.ttf
Binary file not shown.
Binary file removed proplot/fonts/HelveticaNeueBoldItalic.ttf
Binary file not shown.
Binary file removed proplot/fonts/HelveticaNeueItalic.ttf
Binary file not shown.
Binary file removed proplot/fonts/HelveticaNeueMedium.ttf
Binary file not shown.
Binary file removed proplot/fonts/HelveticaNeueMediumItalic.ttf
Binary file not shown.
Binary file removed proplot/fonts/HelveticaOblique.ttf
Binary file not shown.
Binary file removed proplot/fonts/LucidaGrande.ttc
Binary file not shown.
Binary file removed proplot/fonts/LucidaGrande_0.ttf
Binary file not shown.
Binary file removed proplot/fonts/LucidaGrande_1.ttf
Binary file not shown.
Binary file removed proplot/fonts/MyriadPro-Bold.otf
Binary file not shown.
Binary file removed proplot/fonts/MyriadPro-BoldCond.otf
Binary file not shown.
Binary file removed proplot/fonts/MyriadPro-BoldCondIt.otf
Binary file not shown.
Binary file removed proplot/fonts/MyriadPro-BoldIt.otf
Binary file not shown.
Binary file removed proplot/fonts/MyriadPro-Cond.otf
Binary file not shown.
Binary file removed proplot/fonts/MyriadPro-CondIt.otf
Binary file not shown.
Binary file removed proplot/fonts/MyriadPro-It.otf
Binary file not shown.
Binary file removed proplot/fonts/MyriadPro-Regular.otf
Binary file not shown.
Binary file removed proplot/fonts/MyriadPro-Semibold.otf
Binary file not shown.
Binary file removed proplot/fonts/MyriadPro-SemiboldIt.otf
Binary file not shown.
Binary file removed proplot/fonts/Optima.ttc
Binary file not shown.
Binary file removed proplot/fonts/Optima_0.ttf
Binary file not shown.
Binary file removed proplot/fonts/Optima_1.ttf
Binary file not shown.
Binary file removed proplot/fonts/Optima_2.ttf
Binary file not shown.
Binary file removed proplot/fonts/Optima_3.ttf
Binary file not shown.
Binary file removed proplot/fonts/Optima_4.ttf
Binary file not shown.
Binary file removed proplot/fonts/Tahoma Bold.ttf
Binary file not shown.
Binary file removed proplot/fonts/Tahoma.ttf
Binary file not shown.
Binary file removed proplot/fonts/Trebuchet MS Bold Italic.ttf
Binary file not shown.
Binary file removed proplot/fonts/Trebuchet MS Bold.ttf
Binary file not shown.
Binary file removed proplot/fonts/Trebuchet MS Italic.ttf
Binary file not shown.
Binary file removed proplot/fonts/Trebuchet MS.ttf
Binary file not shown.
Binary file removed proplot/fonts/Univers-Bold.otf
Binary file not shown.
Binary file removed proplot/fonts/Univers-BoldOblique.otf
Binary file not shown.
Binary file removed proplot/fonts/Univers-Oblique.otf
Binary file not shown.
Binary file removed proplot/fonts/Univers.otf
Binary file not shown.
Binary file removed proplot/fonts/Verdana Bold Italic.ttf
Binary file not shown.
Binary file removed proplot/fonts/Verdana Bold.ttf
Binary file not shown.
Binary file removed proplot/fonts/Verdana Italic.ttf
Binary file not shown.
Binary file removed proplot/fonts/Verdana.ttf
Binary file not shown.
40 changes: 34 additions & 6 deletions proplot/rctools.py
Expand Up @@ -7,7 +7,7 @@
# new settings! Much of this script was adapted from seaborn; see:
# https://github.com/mwaskom/seaborn/blob/master/seaborn/rcmod.py
from matplotlib import rcParams as rcParams
from .utils import _warn_proplot, _counter, _timer, _benchmark, units
from .utils import _warn_proplot, _counter, _benchmark, units
import re
import os
import yaml
Expand All @@ -25,7 +25,8 @@ def get_ipython():
return None
__all__ = [
'rc', 'rc_configurator', 'ipython_autosave',
'ipython_autoreload', 'ipython_matplotlib'
'ipython_autoreload', 'ipython_matplotlib',
'use_font',
]

# Initialize
Expand All @@ -35,9 +36,6 @@ def get_ipython():
# "Global" settings and the lower-level settings they change
# NOTE: This whole section, declaring dictionaries and sets, takes 1ms
RC_CHILDREN = {
'fontname': (
'font.family',
),
'cmap': (
'image.cmap',
),
Expand Down Expand Up @@ -533,6 +531,8 @@ def __setitem__(self, key, value):
ipython_autosave(value)
if key == 'autoreload':
ipython_autoreload(value)
if key == 'fontname':
use_font(value)
if key == 'rgbcycle': # if must re-apply cycler afterward
cache[key] = value
rcParamsShort[key] = value
Expand Down Expand Up @@ -873,7 +873,6 @@ def reset(self):
return self.__init__()


@_timer
def ipython_matplotlib(backend=None, fmt=None):
"""
Set up the `matplotlib backend \
Expand Down Expand Up @@ -1002,11 +1001,40 @@ def ipython_autosave(autosave=None):
pass


def use_font(font=None):
"""
Set the default font and ensure that the font used for TeX-style math
is the same as the regular font by applying
``rcParams['mathtext.default'] = 'regular'``.
Parameters
----------
font : str, optional
If ``'auto'``, we search for ``'Helvetica Neue'``, followed by
``'Helvetica'``, ``'Arial'``, and finally ``'DejaVu Sans'``.
"""
font = font or rcParamsShort['fontname']
if font == 'auto':
import matplotlib.font_manager as mfonts
font = 'DejaVu Sans'
fonts = sorted({font.name for font in mfonts.fontManager.ttflist})
for nicefont in (
'Helvetica Neue', 'Helvetica', 'Arial',
'DejaVu Sans', 'Bitstream Vera',
):
if nicefont in fonts:
font = nicefont
break
rcParams['font.family'] = font
rcParams['mathtext.default'] = 'regular'


#: Instance of `rc_configurator`. This is used to change global settings.
#: See :ref:`Configuring proplot` for details.
rc = rc_configurator()

# Call setup functions
use_font()
ipython_matplotlib()
ipython_autoreload()
ipython_autosave()

0 comments on commit ddbc23f

Please sign in to comment.