def setup_method(self, method): import matplotlib as mpl from pandas.plotting._matplotlib import compat self.compat = compat mpl.rcdefaults() self.start_date_to_int64 = 812419200000000000 self.end_date_to_int64 = 819331200000000000 self.mpl_ge_2_2_3 = compat.mpl_ge_2_2_3() self.mpl_ge_3_0_0 = compat.mpl_ge_3_0_0() self.mpl_ge_3_1_0 = compat.mpl_ge_3_1_0() self.mpl_ge_3_2_0 = compat.mpl_ge_3_2_0() self.bp_n_objects = 7 self.polycollection_factor = 2 self.default_figsize = (6.4, 4.8) self.default_tick_position = "left" n = 100 with tm.RNGContext(42): gender = np.random.choice(["Male", "Female"], size=n) classroom = np.random.choice(["A", "B", "C"], size=n) self.hist_df = DataFrame({ "gender": gender, "classroom": classroom, "height": np.random.normal(66, 4, size=n), "weight": np.random.normal(161, 32, size=n), "category": np.random.randint(4, size=n), "datetime": to_datetime( np.random.randint( self.start_date_to_int64, self.end_date_to_int64, size=n, dtype=np.int64, )), }) self.tdf = tm.makeTimeDataFrame() self.hexbin_df = DataFrame({ "A": np.random.uniform(size=20), "B": np.random.uniform(size=20), "C": np.arange(20) + np.random.uniform(size=20), })
def handle_shared_axes( axarr: Iterable[Axes], nplots: int, naxes: int, nrows: int, ncols: int, sharex: bool, sharey: bool, ): if nplots > 1: if compat.mpl_ge_3_2_0(): row_num = lambda x: x.get_subplotspec().rowspan.start col_num = lambda x: x.get_subplotspec().colspan.start else: row_num = lambda x: x.rowNum col_num = lambda x: x.colNum if compat.mpl_ge_3_4_0(): is_first_col = lambda x: x.get_subplotspec().is_first_col() else: is_first_col = lambda x: x.is_first_col() if nrows > 1: try: # first find out the ax layout, # so that we can correctly handle 'gaps" layout = np.zeros((nrows + 1, ncols + 1), dtype=np.bool_) for ax in axarr: layout[row_num(ax), col_num(ax)] = ax.get_visible() for ax in axarr: # only the last row of subplots should get x labels -> all # other off layout handles the case that the subplot is # the last in the column, because below is no subplot/gap. if not layout[row_num(ax) + 1, col_num(ax)]: continue if sharex or _has_externally_shared_axis(ax, "x"): _remove_labels_from_axis(ax.xaxis) except IndexError: # if gridspec is used, ax.rowNum and ax.colNum may different # from layout shape. in this case, use last_row logic for ax in axarr: if ax.is_last_row(): continue if sharex or _has_externally_shared_axis(ax, "x"): _remove_labels_from_axis(ax.xaxis) if ncols > 1: for ax in axarr: # only the first column should get y labels -> set all other to # off as we only have labels in the first column and we always # have a subplot there, we can skip the layout test if is_first_col(ax): continue if sharey or _has_externally_shared_axis(ax, "y"): _remove_labels_from_axis(ax.yaxis)