diff --git a/scripts/tip-color-range.py b/scripts/tip-color-range.py deleted file mode 100644 index b8b43eb..0000000 --- a/scripts/tip-color-range.py +++ /dev/null @@ -1,24 +0,0 @@ -# ----------------------------------------------------------------------------- -# Matplotlib cheat sheet -# Released under the BSD License -# ----------------------------------------------------------------------------- - -# Scripts to generate all the basic plots -import numpy as np -import matplotlib as mpl -import matplotlib.pyplot as plt - -fig = plt.figure(figsize=(2, 2)) -mpl.rcParams['axes.linewidth'] = 1.5 -d = 0.01 - -ax = fig.add_axes([d, d, 1-2*d, 1-2*d], xticks=[], yticks=[]) - -X = np.random.seed(1) -X = np.random.randn(1000, 4) -cmap = plt.get_cmap("Oranges") -colors = [cmap(i) for i in [.1, .3, .5, .7]] -ax.hist(X, 2, density=True, histtype='bar', color=colors) - -plt.savefig("../figures/tip-color-range.pdf") -# plt.show() diff --git a/scripts/tip-colorbar.py b/scripts/tip-colorbar.py deleted file mode 100644 index 2a46357..0000000 --- a/scripts/tip-colorbar.py +++ /dev/null @@ -1,25 +0,0 @@ -# ----------------------------------------------------------------------------- -# Matplotlib cheat sheet -# Released under the BSD License -# ----------------------------------------------------------------------------- - -# Scripts to generate all the basic plots -import numpy as np -import matplotlib as mpl -import matplotlib.pyplot as plt -import matplotlib.patheffects as path_effects - -fig = plt.figure(figsize=(2.15, 2)) -mpl.rcParams['axes.linewidth'] = 1.5 -d = 0.01 -ax = fig.add_axes([d, d, 1-2*d, 1-2*d], xticks=[], yticks=[]) - -np.random.seed(1) -Z = np.random.uniform(0, 1, (8, 8)) -cmap = plt.get_cmap("Oranges") -im = ax.imshow(Z, interpolation="nearest", cmap=cmap, vmin=0, vmax=2) -cb = fig.colorbar(im, fraction=0.046, pad=0.04) -cb.set_ticks([]) - -plt.savefig("../figures/tip-colorbar.pdf") -# plt.show() diff --git a/scripts/tip-dotted.py b/scripts/tip-dotted.py deleted file mode 100644 index ebfae99..0000000 --- a/scripts/tip-dotted.py +++ /dev/null @@ -1,21 +0,0 @@ -# ----------------------------------------------------------------------------- -# Matplotlib cheat sheet -# Released under the BSD License -# ----------------------------------------------------------------------------- - -# Scripts to generate all the basic plots -import numpy as np -import matplotlib as mpl -import matplotlib.pyplot as plt -fig = plt.figure(figsize=(5, .25)) - -ax = fig.add_axes([0, 0, 1, 1], frameon=False, - xticks=[], yticks=[], xlim=[0, 1], ylim=[-.5, 1.5]) - -epsilon=1e-12 -plt.plot([0, 1], [0, 0], "black", clip_on=False, lw=8, - ls=(.5, (epsilon, 1)), dash_capstyle="round") -plt.plot([0, 1], [1, 1], "black", clip_on=False, lw=8, - ls=(-.5, (epsilon, 2)), dash_capstyle="round") -plt.savefig("../figures/tip-dotted.pdf") -# plt.show() diff --git a/scripts/tip-dual-axis.py b/scripts/tip-dual-axis.py deleted file mode 100644 index 74677eb..0000000 --- a/scripts/tip-dual-axis.py +++ /dev/null @@ -1,25 +0,0 @@ -import numpy as np -import matplotlib as mpl -import matplotlib.pyplot as plt -mpl.rcParams['axes.linewidth'] = 1.5 - - -fig = plt.figure(figsize=(2, 2)) -d = 0.01 -ax1 = fig.add_axes([d, d, 1-2*d, 1-2*d], label="cartesian") -ax2 = fig.add_axes([d, d, 1-2*d, 1-2*d], projection="polar", label="polar") - -ax1.set_xticks([]) # np.linspace(0.0, 0.4, 5)) -ax1.set_yticks([]) # np.linspace(0.0, 1.0, 11)) - -ax2.set_rorigin(0) -ax2.set_thetamax(90) -ax2.set_ylim(0.5, 1.0) -ax2.set_xticks(np.linspace(0, np.pi/2, 10)) -ax2.set_yticks(np.linspace(0.5, 1.0, 5)) - -ax2.set_xticklabels([]) -ax2.set_yticklabels([]) - -plt.savefig("../figures/tip-dual-axis.pdf") -# plt.show() diff --git a/scripts/tip-font-family.py b/scripts/tip-font-family.py deleted file mode 100644 index 8689b3b..0000000 --- a/scripts/tip-font-family.py +++ /dev/null @@ -1,50 +0,0 @@ -# ---------------------------------------------------------------------------- -# Title: Scientific Visualisation - Python & Matplotlib -# Author: Nicolas P. Rougier -# License: BSD -# ---------------------------------------------------------------------------- -import numpy as np -import matplotlib.pyplot as plt -import matplotlib.ticker as ticker - -# Setup a plot such that only the bottom spine is shown - - -def setup(ax): - ax.spines['right'].set_color('none') - ax.spines['left'].set_color('none') - ax.yaxis.set_major_locator(ticker.NullLocator()) - ax.spines['top'].set_color('none') - - ax.spines['bottom'].set_position("center") - - ax.xaxis.set_ticks_position('bottom') - ax.tick_params(which='major', width=1.00) - ax.tick_params(which='major', length=5) - ax.tick_params(which='minor', width=0.75) - ax.tick_params(which='minor', length=2.5) - ax.set_xlim(0, 5) - ax.set_ylim(0, 1) - ax.patch.set_alpha(0.0) - - -fig = plt.figure(figsize=(5, .5)) -fig.patch.set_alpha(0.0) -n = 1 - -fontsize = 18 -ax = plt.subplot(n, 1, 1) -ax.tick_params(axis='both', which='minor', labelsize=6) -setup(ax) -ax.xaxis.set_major_locator(ticker.MultipleLocator(1.0)) -ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.2)) -ax.xaxis.set_major_formatter(ticker.ScalarFormatter()) -ax.xaxis.set_minor_formatter(ticker.ScalarFormatter()) -ax.tick_params(axis='x', which='minor', rotation=0) - -for tick in ax.get_xticklabels(which='both'): - tick.set_fontname("Roboto Condensed") - -plt.tight_layout() -plt.savefig("../figures/tip-font-family.pdf", transparent=True) -# plt.show() diff --git a/scripts/tip-hatched.py b/scripts/tip-hatched.py deleted file mode 100644 index c8a4ec3..0000000 --- a/scripts/tip-hatched.py +++ /dev/null @@ -1,40 +0,0 @@ -import numpy as np -import matplotlib.pyplot as plt - -cmap = plt.get_cmap("Oranges") -color1, color2 = cmap(0.3), cmap(0.5) - -plt.rcParams['hatch.color'] = color1 -plt.rcParams['hatch.linewidth'] = 8 - -fig = plt.figure(figsize=(2, 2)) -ax = plt.subplot() -np.random.seed(123) - -x1, y1 = 3*np.arange(2), np.random.randint(25, 50, 2) -x2, y2 = x1+1, np.random.randint(25, 75, 2) - -ax.bar(x1, y1, color=color2) -for i in range(len(x1)): - plt.annotate("%d%%" % y1[i], (x1[i], y1[i]), xytext=(0, 1), - fontsize="x-small", color=color2, - textcoords="offset points", va="bottom", ha="center") - -ax.bar(x2, y2, color=color2, hatch="/" ) -for i in range(len(x2)): - plt.annotate("%d%%" % y2[i], (x2[i], y2[i]), xytext=(0, 1), - fontsize="x-small", color=color2, - textcoords="offset points", va="bottom", ha="center") - -ax.set_yticks([]) -ax.set_xticks(0.5+np.arange(0, 6, 3)) -ax.set_xticklabels(["2018", "2019"]) -ax.tick_params('x', length=0, labelsize="small", which='major') - -ax.spines['right'].set_visible(False) -ax.spines['left'].set_visible(False) -ax.spines['top'].set_visible(False) - -plt.tight_layout() -plt.savefig("../figures/tip-hatched.pdf") -# plt.show() diff --git a/scripts/tip-multiline.py b/scripts/tip-multiline.py deleted file mode 100644 index 1b62b76..0000000 --- a/scripts/tip-multiline.py +++ /dev/null @@ -1,24 +0,0 @@ -# ---------------------------------------------------------------------------- -# Author: Nicolas P. Rougier -# License: BSD -# ---------------------------------------------------------------------------- -import numpy as np -import matplotlib as mpl -import matplotlib.pyplot as plt -mpl.rcParams['axes.linewidth'] = 1.5 - -fig = plt.figure(figsize=(8, 1.5)) -dx, dy = 0.0025, 0.01 -ax = fig.add_axes([dx, dy, 1-2*dx, 1-2*dy], frameon=False) -X, Y = [], [] -for x in np.linspace(0.01, 10*np.pi-0.01, 100): - X.extend([x, x, None]) - Y.extend([0, np.sin(x), None]) -print(X[:10], Y[:10]) -plt.plot(X, Y, "black") -plt.xticks([]), plt.yticks([]) -plt.xlim(-0.25, 10*np.pi+.25) -plt.ylim(-1.5, 1.5) -plt.tight_layout() -plt.savefig("../figures/tip-multiline.pdf", dpi=100) -# plt.show() diff --git a/scripts/tip-outline.py b/scripts/tip-outline.py deleted file mode 100644 index e376149..0000000 --- a/scripts/tip-outline.py +++ /dev/null @@ -1,27 +0,0 @@ -# ----------------------------------------------------------------------------- -# Matplotlib cheat sheet -# Released under the BSD License -# ----------------------------------------------------------------------------- - -# Scripts to generate all the basic plots -import numpy as np -import matplotlib as mpl -import matplotlib.pyplot as plt -import matplotlib.patheffects as path_effects - -fig = plt.figure(figsize=(2, 2)) -mpl.rcParams['axes.linewidth'] = 1.5 -d = 0.01 - -ax = fig.add_axes([d, d, 1-2*d, 1-2*d], xticks=[], yticks=[]) - -np.random.seed(1) -Z = np.random.uniform(0, 1, (8, 8)) -cmap = plt.get_cmap("Oranges") -ax.imshow(Z, interpolation="nearest", cmap=cmap, vmin=0, vmax=2) - -text = ax.text(0.5, 0.1, "Label", transform=ax.transAxes, - color=cmap(0.9), size=32, weight="bold", ha="center", va="bottom") -text.set_path_effects([path_effects.Stroke(linewidth=5, foreground='white'), - path_effects.Normal()]) -plt.savefig("../figures/tip-outline.pdf") diff --git a/scripts/tip-post-processing.py b/scripts/tip-post-processing.py deleted file mode 100644 index 4086d03..0000000 --- a/scripts/tip-post-processing.py +++ /dev/null @@ -1,27 +0,0 @@ -import numpy as np -import matplotlib.pyplot as plt -from matplotlib.figure import Figure -from matplotlib.backends.backend_agg import FigureCanvas -from scipy.ndimage import gaussian_filter - -# First pass for drop-shadow -fig = Figure(figsize=(6, 1.5)) -canvas = FigureCanvas(fig) -ax = fig.add_axes([0, 0, 1, 1], frameon=False, - xlim=[0, 1], xticks=[], ylim=[0, 1], yticks=[]) -ax.text(0.5, 0.5, "Matplotlib", transform=ax.transAxes, - ha="center", va="center", size=64, color="black") -canvas.draw() -Z = np.array(canvas.renderer.buffer_rgba())[:, :, 0] -Z = gaussian_filter(Z, sigma=9) - -# Second pass for text + drop-shadow -fig = plt.figure(figsize=(6, 1.5)) -ax = fig.add_axes([0, 0, 1, 1], frameon=False, - xlim=[0, 1], xticks=[], ylim=[0, 1], yticks=[]) -ax.imshow(Z, extent=[0, 1, 0, 1], cmap=plt.cm.gray, alpha=0.65, aspect='auto') -ax.text(0.5, 0.5, "Matplotlib", transform=ax.transAxes, - ha="center", va="center", size=64, color="black") - -plt.savefig("../figures/tip-post-processing.pdf", dpi=600) -# plt.show() diff --git a/scripts/tip-transparency.py b/scripts/tip-transparency.py deleted file mode 100644 index 2d9abc6..0000000 --- a/scripts/tip-transparency.py +++ /dev/null @@ -1,25 +0,0 @@ -# ----------------------------------------------------------------------------- -# Matplotlib cheat sheet -# Released under the BSD License -# ----------------------------------------------------------------------------- -import numpy as np -import matplotlib as mpl -import matplotlib.pyplot as plt -mpl.rc('axes', linewidth=1.5) - -np.random.seed(123) - -fig = plt.figure(figsize=(2, 2), dpi=100) -margin = 0.01 -ax = fig.add_axes([margin, margin, 1-2*margin, 1-2*margin]) -n = 500 -X = np.random.normal(0, 0.25, n) -Y = np.random.normal(0, 0.25, n) -ax.scatter(X, Y, s=50, c="k", lw=2) -ax.scatter(X, Y, s=50, c="w", lw=0) -ax.scatter(X, Y, s=40, c="C1", lw=0, alpha=0.1) - -ax.set_xlim([-1, 1]), ax.set_xticks([]), -ax.set_ylim([-1, 1]), ax.set_yticks([]) -plt.savefig("../figures/tip-transparency.pdf") -# plt.show() diff --git a/scripts/tips.py b/scripts/tips.py new file mode 100644 index 0000000..e8b196a --- /dev/null +++ b/scripts/tips.py @@ -0,0 +1,217 @@ +# ----------------------------------------------------------------------------- +# Matplotlib cheat sheet +# Released under the BSD License +# ----------------------------------------------------------------------------- + +# Script to generate the tips +import numpy as np +import matplotlib as mpl +import matplotlib.pyplot as plt +import matplotlib.patheffects as path_effects + + +mpl.rcParams['axes.linewidth'] = 1.5 + +margin = 0.01 +rect = [margin, margin, 1-2*margin, 1-2*margin] + + +# color range +# ----------------------------------------------------------------------------- +fig = plt.figure(figsize=(2, 2)) +ax = fig.add_axes(rect, xticks=[], yticks=[]) + +np.random.seed(1) +X = np.random.randn(1000, 4) +cmap = plt.get_cmap("Oranges") +colors = [cmap(i) for i in [0.1, 0.3, 0.5, 0.7]] +ax.hist(X, 2, density=True, histtype='bar', color=colors) + +fig.savefig("../figures/tip-color-range.pdf") + + +# colorbar +# ----------------------------------------------------------------------------- +fig = plt.figure(figsize=(2.15, 2)) +ax = fig.add_axes(rect, xticks=[], yticks=[]) + +np.random.seed(1) +Z = np.random.uniform(0, 1, (8, 8)) +cmap = plt.get_cmap("Oranges") +im = ax.imshow(Z, interpolation="nearest", cmap=cmap, vmin=0, vmax=2) +cb = fig.colorbar(im, fraction=0.046, pad=0.04) +cb.set_ticks([]) + +fig.savefig("../figures/tip-colorbar.pdf") + + +# dotted +# ----------------------------------------------------------------------------- +fig = plt.figure(figsize=(5, 0.25)) + +ax = fig.add_axes( + [0, 0, 1, 1], frameon=False, xticks=[], yticks=[], xlim=[0, 1], ylim=[-0.5, 1.5] +) + +epsilon=1e-12 +ax.plot([0, 1], [0, 0], "black", clip_on=False, lw=8, + ls=(.5, (epsilon, 1)), dash_capstyle="round") +ax.plot([0, 1], [1, 1], "black", clip_on=False, lw=8, + ls=(-.5, (epsilon, 2)), dash_capstyle="round") +fig.savefig("../figures/tip-dotted.pdf") + + +# dual axis +# ----------------------------------------------------------------------------- +fig = plt.figure(figsize=(2, 2)) +ax1 = fig.add_axes(rect, label="cartesian") +ax2 = fig.add_axes(rect, projection="polar", label="polar") + +ax1.set_xticks([]) # np.linspace(0.0, 0.4, 5)) +ax1.set_yticks([]) # np.linspace(0.0, 1.0, 11)) + +ax2.set_rorigin(0) +ax2.set_thetamax(90) +ax2.set_ylim(0.5, 1.0) +ax2.set_xticks(np.linspace(0, np.pi/2, 10)) +ax2.set_yticks(np.linspace(0.5, 1.0, 5)) + +ax2.set_xticklabels([]) +ax2.set_yticklabels([]) + +fig.savefig("../figures/tip-dual-axis.pdf") + + +# font family +# ----------------------------------------------------------------------------- +# Setup a plot such that only the bottom spine is shown +def setup(ax): + ax.spines['right'].set_color('none') + ax.spines['left'].set_color('none') + ax.yaxis.set_major_locator(mpl.ticker.NullLocator()) + ax.spines['top'].set_color('none') + + ax.spines['bottom'].set_linewidth(1) + ax.spines['bottom'].set_position("center") + + ax.xaxis.set_ticks_position('bottom') + ax.tick_params(which='major', width=1.00) + ax.tick_params(which='major', length=5) + ax.tick_params(which='minor', width=0.75) + ax.tick_params(which='minor', length=2.5) + ax.set_xlim(0, 5) + ax.set_ylim(0, 1) + ax.patch.set_alpha(0.0) + + +fig = plt.figure(figsize=(5, 0.5)) +fig.patch.set_alpha(0.0) +n = 1 + +fontsize = 18 +ax = plt.subplot(n, 1, 1) +ax.tick_params(axis='both', which='minor', labelsize=6) +setup(ax) +ax.xaxis.set_major_locator(mpl.ticker.MultipleLocator(1.0)) +ax.xaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.2)) +ax.xaxis.set_major_formatter(mpl.ticker.ScalarFormatter()) +ax.xaxis.set_minor_formatter(mpl.ticker.ScalarFormatter()) +ax.tick_params(axis='x', which='minor', rotation=0) + +for tick in ax.get_xticklabels(which='both'): + tick.set_fontname("Roboto Condensed") + +fig.tight_layout() +fig.savefig("../figures/tip-font-family.pdf", transparent=True) + + +# hatched +# ----------------------------------------------------------------------------- +cmap = plt.get_cmap("Oranges") +color1, color2 = cmap(0.3), cmap(0.5) + +mpl.rcParams['hatch.color'] = color1 +mpl.rcParams['hatch.linewidth'] = 8 + +fig = plt.figure(figsize=(2, 2)) +ax = plt.subplot() +np.random.seed(123) + +x1, y1 = 3 * np.arange(2), np.random.randint(25, 50, 2) +x2, y2 = x1 + 1, np.random.randint(25, 75, 2) + +ax.bar(x1, y1, color=color2) +for i in range(len(x1)): + ax.annotate("%d%%" % y1[i], (x1[i], y1[i]), xytext=(0, 1), + fontsize="x-small", color=color2, + textcoords="offset points", va="bottom", ha="center") + +ax.bar(x2, y2, color=color2, hatch="/") +for i in range(len(x2)): + ax.annotate("%d%%" % y2[i], (x2[i], y2[i]), xytext=(0, 1), + fontsize="x-small", color=color2, + textcoords="offset points", va="bottom", ha="center") + +ax.set_yticks([]) +ax.set_xticks(0.5 + np.arange(0, 6, 3)) +ax.set_xticklabels(["2018", "2019"]) +ax.tick_params('x', length=0, labelsize="small", which='major') + +ax.spines['right'].set_visible(False) +ax.spines['left'].set_visible(False) +ax.spines['top'].set_visible(False) + +fig.tight_layout() +fig.savefig("../figures/tip-hatched.pdf") + + +# multiline +# ----------------------------------------------------------------------------- +fig = plt.figure(figsize=(8, 1.5)) +dx, dy = 0.0025, 0.01 +ax = fig.add_axes([dx, dy, 1-2*dx, 1-2*dy], frameon=False) +X, Y = [], [] +for x in np.linspace(0.01, 10*np.pi-0.01, 100): + X.extend([x, x, None]) + Y.extend([0, np.sin(x), None]) +print(X[:10], Y[:10]) +ax.plot(X, Y, "black") +ax.set_xticks([]), ax.set_yticks([]) +ax.set_xlim(-0.25, 10*np.pi+0.25) +ax.set_ylim(-1.5, 1.5) +fig.tight_layout() +fig.savefig("../figures/tip-multiline.pdf", dpi=100) + + +# outline +# ----------------------------------------------------------------------------- +fig = plt.figure(figsize=(2, 2)) +ax = fig.add_axes(rect, xticks=[], yticks=[]) + +np.random.seed(1) +Z = np.random.uniform(0, 1, (8, 8)) +cmap = plt.get_cmap("Oranges") +ax.imshow(Z, interpolation="nearest", cmap=cmap, vmin=0, vmax=2) + +text = ax.text(0.5, 0.1, "Label", transform=ax.transAxes, + color=cmap(0.9), size=32, weight="bold", ha="center", va="bottom") +text.set_path_effects([path_effects.Stroke(linewidth=5, foreground='white'), + path_effects.Normal()]) +fig.savefig("../figures/tip-outline.pdf") + + +# transparency +# ----------------------------------------------------------------------------- +fig = plt.figure(figsize=(2, 2), dpi=100) +ax = fig.add_axes(rect) +n = 500 +np.random.seed(5) +X = np.random.normal(0, 0.25, n) +Y = np.random.normal(0, 0.25, n) +ax.scatter(X, Y, s=50, c="k", lw=2) +ax.scatter(X, Y, s=50, c="w", lw=0) +ax.scatter(X, Y, s=40, c="C1", lw=0, alpha=0.1) + +ax.set_xlim([-1, 1]), ax.set_xticks([]), +ax.set_ylim([-1, 1]), ax.set_yticks([]) +fig.savefig("../figures/tip-transparency.pdf")