def test_style_context_manager(self): rcmod.set_style("darkgrid") orig_params = rcmod.axes_style() context_params = rcmod.axes_style("whitegrid") with rcmod.axes_style("whitegrid"): self.assert_rc_params(context_params) self.assert_rc_params(orig_params) @rcmod.axes_style("whitegrid") def func(): self.assert_rc_params(context_params) func() self.assert_rc_params(orig_params)
def plot_axis(self,data,idx,cmap,strf='%a\n%d\n%h\n%Y',fontsize=20, pct_space=0.1): #display original array as index xticks_ix = int(math.ceil(len(data)/100)*1/pct_space) xticks_vals = np.arange(len(data))[::xticks_ix] xticks_labels = data[::xticks_ix] with axes_style("white"): f, ax = plt.subplots(figsize=(10, 1)) if True:#idx.ndim <= 1: idx_plot = np.tile(idx, (1, 1)) else: idx_plot = idx ax.pcolormesh(idx_plot,cmap=cmap) if self.is_time_array(data): ticks = pd.DatetimeIndex(xticks_labels).to_pydatetime() _ = plt.xticks(xticks_vals, [x.strftime(strf) for x in ticks], fontsize = fontsize, rotation=self.vertical.value) else: _ = plt.xticks(xticks_vals, xticks_labels, fontsize = fontsize, rotation=self.vertical.value) ax.axis([0,len(data), 0, 1]) ax.axes.get_yaxis().set_visible(False) #f.tight_layout() html = self.fig_to_html(f,img_class='axisplot') plt.close(f) return html
def test_set_style(self): for style in self.styles: style_dict = rcmod.axes_style(style) rcmod.set_style(style) self.assert_rc_params(style_dict)
def _show_cmap(cmap): """Show a continuous matplotlib colormap.""" from seaborn.rcmod import axes_style # Avoid circular import with axes_style("white"): f, ax = plt.subplots(figsize=(13.25, .75)) ax.set(xticks=[], yticks=[]) x = np.linspace(0, 1, 256)[np.newaxis, :] ax.pcolormesh(x, cmap=cmap)
def plot_axis(self, data, idx, cmap, strf='%a\n%d\n%h\n%Y', fontsize=20, pct_space=0.1): #display original array as index xticks_ix = int(math.ceil(len(data) / 100) * 1 / pct_space) xticks_vals = np.arange(len(data))[::xticks_ix] xticks_labels = data[::xticks_ix] with axes_style("white"): f, ax = plt.subplots(figsize=(10, 1)) if True: #idx.ndim <= 1: idx_plot = np.tile(idx, (1, 1)) else: idx_plot = idx ax.pcolormesh(idx_plot, cmap=cmap) if self.is_time_array(data): ticks = pd.DatetimeIndex(xticks_labels).to_pydatetime() _ = plt.xticks(xticks_vals, [x.strftime(strf) for x in ticks], fontsize=fontsize, rotation=self.orient) else: _ = plt.xticks(xticks_vals, xticks_labels, fontsize=fontsize, rotation=self.orient) ax.axis([0, len(data), 0, 1]) ax.axes.get_yaxis().set_visible(False) #f.tight_layout() html = self.fig_to_html(f, img_class='axisplot') plt.close(f) return html
def test_rc_override(self): rc = {"axes.facecolor": "blue", "foo.notaparam": "bar"} out = rcmod.axes_style("darkgrid", rc) assert out["axes.facecolor"] == "blue" assert "foo.notaparam" not in out
def test_bad_style(self): with pytest.raises(ValueError): rcmod.axes_style("i_am_not_a_style")
def test_key_usage(self): _style_keys = set(rcmod._style_keys) for style in self.styles: assert not set(rcmod.axes_style(style)) ^ _style_keys
def test_default_return(self): current = rcmod.axes_style() self.assert_rc_params(current)