ax.add_patch(Rectangle((0, 0), arc, 10.5, facecolor='white', zorder=0, clip_on=False, in_layout=False)) return ax def make_logo(height_px): """ Create a figure with the prettypyplot logo. Parameters ---------- height_px : int Height of the figure in pixel. """ dpi = plt.rcParams['figure.dpi'] height = height_px / dpi figsize = (height, height) fig = plt.figure(figsize=figsize) ax = create_icon_axes(fig) return fig, ax if __name__ == '__main__': pplt.use_style() fig, ax = make_logo(height_px=120) pplt.savefig('gallery/logo.png')
"""Create Matplotlib inspired logo. This script is taken from https://matplotlib.org/gallery/misc/logos2.html#sphx-glr-gallery-misc-logos2-py an heavily simplified to fit the spirit of prettypyplot. """ import prettypyplot as pplt import logo pplt.use_style(latex=False) fig, ax = logo.make_logo(height_px=120) pplt.figtext( 1.4, 1.15, 'prettypyplot', va='top', ha='left', fontsize=8, weight='bold', fontname='Roboto', ) _, clight, _, _ = pplt.categorical_color(4, 'pplt:gray') pplt.figtext( 1.4, 0.6, 'Publication ready\nmatplotlib figures\nmade simple',
import numpy as np import prettypyplot as pplt # ~~~ DEFINE DATA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ np.random.seed(1337) N = 500 T = np.linspace(0, 3 * np.pi, N) X1, X2, X3 = [ np.sin(T + np.pi * np.random.rand()) + 0.1 * np.random.rand(N) for _ in range(3) ] for style in ['default', 'minimal']: for mode in ['default', 'print', 'beamer']: pplt.use_style(style=style, mode=mode, figsize=2) fig, axs = plt.subplots( 3, 1, gridspec_kw={'hspace': 0.4}, ) # legend for i, outside in enumerate(['top', 'right', False]): ax = axs.flatten()[i] pplt.plot(T, X1, ax=ax, label='$x_1$') pplt.plot(T, X2, ax=ax, label='$x_2$') pplt.plot(T, X3, ax=ax, label='$x_3$') pplt.legend(title='function:', ax=ax, outside=outside)
import prettypyplot as pplt # ~~~ DEFINE DATA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ np.random.seed(1337) n = 1000000 x = np.random.standard_normal(n) y = x + .5 * np.random.standard_normal(n) hist, xedges, yedges = np.histogram2d(x, y, bins=100, density=True) hist[hist == 0] = None t = np.linspace(0, 3 * np.pi, 1000) for style in ['default', 'minimal']: pplt.use_style(style=style) # ~~~ PLOT LINEAR ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fig, ax = plt.subplots() pplt.plot(t, np.sin(t), t, np.cos(t), t, 2 * np.cos(t)) pplt.savefig(f'gallery/{style}_plot.png') plt.close() # legend fig, ax = plt.subplots() pplt.plot(t, np.sin(t), label='sin') pplt.plot(t, np.cos(t), label='cos') pplt.plot(t, 2 * np.cos(t), label='2cos') pplt.legend(title='function:') pplt.savefig(f'gallery/{style}_plot_legend.png') plt.close()
Copyright (c) 2020-2021, Daniel Nagel All rights reserved. """ # ~~~ IMPORT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import matplotlib.pyplot as plt import numpy as np import prettypyplot as pplt # ~~~ DEFINE DATA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ np.random.seed(1337) N = 500 T = np.linspace(0, 3 * np.pi, N) pplt.use_style(figsize=.8) for nfigs in (8, 9): xs = [ np.sin(T + np.pi * np.random.rand()) + 0.1 * np.random.rand(N) for _ in range(nfigs) ] fig, axs = plt.subplots( 3, 3, sharex=True, sharey=True, gridspec_kw={'hspace': 0, 'wspace': 0}, )