In MatPlotTheme, theming MatPlotLib figures is controlled by style and palette, which defines how elements are customized and which colors are used, respectively. As MatPlotTheme provides multiple styles/palettes, using the library is as simple as picking a style-palette combination and plot. What’s more, MatPlotTheme inherits MatPlotLib’s API configuration, which means existing code can be migrated with minimal effort.
MatPlotTheme provides a default Style and a default Palette. Each of them are python classes and all other styles/palettes are derived classes of them. matplottheme provides interfaces to all plotting methods in Style, which enable library usage like matplottheme.plot(ax, x, y).
# Use API provided by matplottheme module import matplottheme as mpt import matplotlib.pylab as plt import numpy as np x = np.arange(1000) y = np.random.normal(size=1000).cumsum() fig = plt.figure() ax = fig.add_subplot(111) # MatPlotTheme plots a line using ggplot2 style/palette mpt.set_theme('ggplot2', 'ggplot2') mpt.plot(ax, x, y)
This code block can also generate the same plot as the first one.
# Use style/palette objects from matplottheme.style.ggplot2 import ggplot2Style from matplottheme.palette.ggplot2 import ggplot2Palette import matplotlib.pylab as plt import numpy as np x = np.arange(1000) y = np.random.normal(size=1000).cumsum() fig = plt.figure() ax = fig.add_subplot(111) # Manually using ggplot2 style/palette ggplot2Style(ggplot2Palette()).plot(ax, x, y)
The MIT License (MIT)
Copyright (c) 2014 James Yu
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.