def test_plot_var_per_category(self): ''' Test the capability of plotting a histogram within different categorical variables ''' output_file = os.path.join(self.out_dir, 'histogram_plot4.png') try: cats = [1, 2, 3, 4, 5] colors = gs.catcmapfromcontinuous("Spectral", 5).colors self.data.catdict = {c: "RT {:02d}".format(c) for c in cats} colordict = {c: colors[i] for i, c in enumerate(cats)} gs.histogram_plot(self.data, var='Phi', cat=True, color=colordict, bins=40, figsize=(8, 4), xlabel=False, output_file=output_file) except Exception as ex: self.fail( 'Unable to test the histogram plot for a variable within different categories \n{}' .format(str(ex))) self.assertEqual(os.path.isfile(output_file), True)
def test_plot_cdf_per_category(self): ''' Test the capability of plotting a cdf within different categorical variables ''' from matplotlib import pyplot as plt output_file = os.path.join(self.out_dir, 'histogram_plot5.png') try: cats = [1, 2, 3, 4, 5] colors = gs.catcmapfromcontinuous("Spectral", 5).colors self.data.catdict = {c: "RT {:02d}".format(c) for c in cats} colordict = {c: colors[i] for i, c in enumerate(cats)} _, axs = plt.subplots(2, 2, figsize=(12, 9)) axs = axs.flatten() for var, ax in zip(self.data.variables, axs): gs.histogram_plot(self.data, var=var, icdf=True, cat=True, color=colordict, ax=ax, output_file=output_file) except Exception as ex: self.fail( 'Unable to test the histogram plot for a variable within different categories \n{}' .format(str(ex))) self.assertEqual(os.path.isfile(output_file), True)
def test_plot_proportions(self): ''' Test the capability of plotting a histogram for categorical proportions ''' from matplotlib import pyplot as plt output_file = os.path.join(self.out_dir, 'histogram_plot6.png') _, ax = plt.subplots(1, 1) try: cats = [1, 2, 3, 4, 5] colors = gs.catcmapfromcontinuous("Spectral", 5).colors self.data.catdict = {c: "RT {:02d}".format(c) for c in cats} colordict = {c: colors[i] for i, c in enumerate(cats)} gs.histogram_plot(self.data, cat=True, color=colordict, bins=40, figsize=(8, 4), xlabel=False, output_file=output_file) gs.histogram_plot(self.data, cat=True, color=colordict, bins=40, figsize=(8, 4), xlabel=False, output_file=output_file, ax=ax) except Exception as ex: self.fail( 'Unable to test the histogram plot for categorical proportions\n{}' .format(str(ex))) self.assertEqual(os.path.isfile(output_file), True)
import pygeostat as gs # load some data dfl = gs.ExampleData("point3d_ind_mv") cats = [1, 2, 3, 4, 5] colors = gs.catcmapfromcontinuous("Spectral", 5).colors # build the required cat dictionaries dfl.catdict = {c: "RT {:02d}".format(c) for c in cats} colordict = {c: colors[i] for i, c in enumerate(cats)} # plot the histogram_plot ax = gs.histogram_plot(dfl, cat=True, color=colordict, figsize=(7, 4), rotateticks=(45, 0), label_count=True)