def _plot_colorbar(self, ax, **kwds): # Addresses issues #10611 and #10678: # When plotting scatterplots and hexbinplots in IPython # inline backend the colorbar axis height tends not to # exactly match the parent axis height. # The difference is due to small fractional differences # in floating points with similar representation. # To deal with this, this method forces the colorbar # height to take the height of the parent axes. # For a more detailed description of the issue # see the following link: # https://github.com/ipython/ipython/issues/11215 img = ax.collections[0] cbar = self.fig.colorbar(img, ax=ax, **kwds) if _mpl_ge_3_0_0(): # The workaround below is no longer necessary. return points = ax.get_position().get_points() cbar_points = cbar.ax.get_position().get_points() cbar.ax.set_position([ cbar_points[0, 0], points[0, 1], cbar_points[1, 0] - cbar_points[0, 0], points[1, 1] - points[0, 1], ])
def test_scatter_matrix_axis(self): from pandas.plotting._matplotlib.compat import _mpl_ge_3_0_0 scatter_matrix = plotting.scatter_matrix with tm.RNGContext(42): df = DataFrame(randn(100, 3)) # we are plotting multiples on a sub-plot with tm.assert_produces_warning( UserWarning, raise_on_extra_warnings=_mpl_ge_3_0_0() ): axes = _check_plot_works( scatter_matrix, filterwarnings="always", frame=df, range_padding=0.1 ) axes0_labels = axes[0][0].yaxis.get_majorticklabels() # GH 5662 expected = ["-2", "0", "2"] self._check_text_labels(axes0_labels, expected) self._check_ticks_props(axes, xlabelsize=8, xrot=90, ylabelsize=8, yrot=0) df[0] = (df[0] - 2) / 3 # we are plotting multiples on a sub-plot with tm.assert_produces_warning(UserWarning): axes = _check_plot_works( scatter_matrix, filterwarnings="always", frame=df, range_padding=0.1 ) axes0_labels = axes[0][0].yaxis.get_majorticklabels() expected = ["-1.0", "-0.5", "0.0"] self._check_text_labels(axes0_labels, expected) self._check_ticks_props(axes, xlabelsize=8, xrot=90, ylabelsize=8, yrot=0)
def setup_method(self, method): import matplotlib as mpl from pandas.plotting._matplotlib import compat mpl.rcdefaults() 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.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': random.normal(66, 4, size=n), 'weight': random.normal(161, 32, size=n), 'category': random.randint(4, size=n)}) 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 setup_method(self, method): import matplotlib as mpl from pandas.plotting._matplotlib import compat mpl.rcdefaults() 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": random.normal(66, 4, size=n), "weight": random.normal(161, 32, size=n), "category": random.randint(4, size=n), } ) 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 setup_method(self, method): import matplotlib as mpl from pandas.plotting._matplotlib import compat mpl.rcdefaults() 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.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': random.normal(66, 4, size=n), 'weight': random.normal(161, 32, size=n), 'category': random.randint(4, size=n) }) 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) })