From ca119149561a000278bc22afbdf9edf05f23e155 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Tue, 27 Oct 2020 19:59:26 +0100 Subject: [PATCH] [statistics] backward compatibility of hist density - still buggy! --- plotstyle.py | 2 +- statistics/lecture/diehistograms.py | 5 ++++- statistics/lecture/displayunivariatedata.py | 2 +- statistics/lecture/kerneldensity.py | 10 ++++++++-- statistics/lecture/pdfhistogram.py | 8 ++++++-- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/plotstyle.py b/plotstyle.py index 06aa015..7c85d36 100644 --- a/plotstyle.py +++ b/plotstyle.py @@ -2,7 +2,7 @@ import matplotlib as mpl import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D -xkcd_style = False +xkcd_style = True # default size of figure: figure_width = 15.0 # cm, should be set according to \textwidth in the latex document diff --git a/statistics/lecture/diehistograms.py b/statistics/lecture/diehistograms.py index 91200f7..c5d03fb 100644 --- a/statistics/lecture/diehistograms.py +++ b/statistics/lecture/diehistograms.py @@ -27,6 +27,9 @@ ax2.set_xlabel('x') ax2.set_ylim(0, 0.23) ax2.set_ylabel('Probability') ax2.plot([0.2, 6.8], [1.0/6.0, 1.0/6.0], zorder=-10, **lsAm) -ax2.hist([x2, x1], bins, density=True, zorder=-5, **fs) +try: + ax2.hist([x2, x1], bins, density=True, zorder=-5, **fs) +except AttributeError: + ax2.hist([x2, x1], bins, normed=True, zorder=-5, **fs) fig.subplots_adjust(left=0.125) fig.savefig('diehistograms.pdf') diff --git a/statistics/lecture/displayunivariatedata.py b/statistics/lecture/displayunivariatedata.py index 31977fe..f56906a 100644 --- a/statistics/lecture/displayunivariatedata.py +++ b/statistics/lecture/displayunivariatedata.py @@ -4,7 +4,7 @@ import matplotlib.gridspec as gridspec from scipy.stats import gaussian_kde from plotstyle import * -sketch_style() +#sketch_style() #rng = np.random.RandomState(981) #data = rng.randn(40, 1) + 4.0 rng = np.random.RandomState(1981) diff --git a/statistics/lecture/kerneldensity.py b/statistics/lecture/kerneldensity.py index 2b608a0..2a0cbb7 100644 --- a/statistics/lecture/kerneldensity.py +++ b/statistics/lecture/kerneldensity.py @@ -44,7 +44,10 @@ ax.set_ylabel('p(x)') ax.set_ylim(0.0, 0.49) ax.set_yticks(np.arange(0.0, 0.41, 0.1)) #ax.plot(x, g, '-b', lw=2, zorder=-1) -ax.hist(r, np.arange(-4.1, 4, 0.4), density=True, zorder=-5, **fsC) +try: + ax.hist(r, np.arange(-4.1, 4, 0.4), density=True, zorder=-5, **fsC) +except AttributeError: + ax.hist(r, np.arange(-4.1, 4, 0.4), normed=True, zorder=-5, **fsC) ax = fig.add_subplot(spec[1, 0]) ax.set_xlabel('x') @@ -54,7 +57,10 @@ ax.set_ylabel('p(x)') ax.set_ylim(0.0, 0.49) ax.set_yticks(np.arange(0.0, 0.41, 0.1)) #ax.plot(x, g, '-b', lw=2, zorder=-1) -ax.hist(r, np.arange(-4.3, 4, 0.4), density=True, zorder=-5, **fsC) +try: + ax.hist(r, np.arange(-4.3, 4, 0.4), density=True, zorder=-5, **fsC) +except AttributeError: + ax.hist(r, np.arange(-4.3, 4, 0.4), normed=True, zorder=-5, **fsC) ax = fig.add_subplot(spec[:, 1]) ax.set_xlabel('x') diff --git a/statistics/lecture/pdfhistogram.py b/statistics/lecture/pdfhistogram.py index cccd146..cddffa6 100644 --- a/statistics/lecture/pdfhistogram.py +++ b/statistics/lecture/pdfhistogram.py @@ -24,8 +24,12 @@ ax2.set_ylabel('Probab. density p(x)') ax2.set_ylim(0.0, 0.44) ax2.set_yticks(np.arange(0.0, 0.41, 0.1)) ax2.plot(x, g, zorder=-1, **lsA) -ax2.hist(r, 5, density=True, zorder=-10, **fsB) -ax2.hist(r, 20, density=True, zorder=-5, **fsC) +try: + ax2.hist(r, 5, density=True, zorder=-10, **fsB) + ax2.hist(r, 20, density=True, zorder=-5, **fsC) +except AttributeError: + ax2.hist(r, 5, normed=True, zorder=-10, **fsB) + ax2.hist(r, 20, normed=True, zorder=-5, **fsC) fig.savefig('pdfhistogram.pdf')