From 2b056b94585a70d6c8ed78e8fa68994c6e82226e Mon Sep 17 00:00:00 2001 From: Sourav Singh Date: Tue, 15 May 2018 08:38:01 +0530 Subject: [PATCH] Create log_tutorial.py --- tutorials/intermediate/log_tutorial.py | 47 ++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tutorials/intermediate/log_tutorial.py diff --git a/tutorials/intermediate/log_tutorial.py b/tutorials/intermediate/log_tutorial.py new file mode 100644 index 000000000000..6e6a841cff8f --- /dev/null +++ b/tutorials/intermediate/log_tutorial.py @@ -0,0 +1,47 @@ +""" +================= +LogScale tutorial +================= +Using LogScale in matplotlib + +LogScale is a class for plotting a logarithmic scale on a plot. +Care is taken to not plot negative values. LogScale provides +different transformations based on the base of the logarithm- + +- base 10 +- base 2 +- base e +- arbitrary base + +""" + +import numpy as np +import matplotlib.pyplot as plt + +plt.subplots_adjust(hspace=0.4) +t = np.arange(0.01, 20.0, 0.01) + +# log y axis +plt.subplot(221) +plt.semilogy(t, np.exp(-t/5.0)) +plt.title('semilogy') +plt.grid(True) + +# log x axis +plt.subplot(222) +plt.semilogx(t, np.sin(2*np.pi*t)) +plt.title('semilogx') +plt.grid(True) + +# log x and y axis +plt.subplot(223) +plt.loglog(t, 20*np.exp(-t/10.0), basex=2) +plt.grid(True) +plt.title('loglog base 2 on x') + +# with errorbars: clip non-positive values +ax = plt.subplot(224) +ax.set_xscale("log", nonposx='clip') +ax.set_yscale("log", nonposy='clip') + +plt.show()