Python matplotlib.ticker.LogLocator() Examples
The following are 30
code examples of matplotlib.ticker.LogLocator().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.ticker
, or try the search function
.
Example #1
Source File: colorbar.py From matplotlib-4-abaqus with MIT License | 6 votes |
def _select_locator(self, formatter): ''' select a suitable locator ''' if self.boundaries is None: if isinstance(self.norm, colors.NoNorm): nv = len(self._values) base = 1 + int(nv/10) locator = ticker.IndexLocator(base=base, offset=0) elif isinstance(self.norm, colors.BoundaryNorm): b = self.norm.boundaries locator = ticker.FixedLocator(b, nbins=10) elif isinstance(self.norm, colors.LogNorm): locator = ticker.LogLocator() else: locator = ticker.MaxNLocator(nbins=5) else: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b) #, nbins=10) self.cbar_axis.set_major_locator(locator)
Example #2
Source File: _base.py From coffeegrindsize with MIT License | 6 votes |
def minorticks_on(self): """ Display minor ticks on the axes. Displaying minor ticks may reduce performance; you may turn them off using `minorticks_off()` if drawing speed is a problem. """ for ax in (self.xaxis, self.yaxis): scale = ax.get_scale() if scale == 'log': s = ax._scale ax.set_minor_locator(mticker.LogLocator(s.base, s.subs)) elif scale == 'symlog': s = ax._scale ax.set_minor_locator( mticker.SymmetricalLogLocator(s._transform, s.subs)) else: ax.set_minor_locator(mticker.AutoMinorLocator())
Example #3
Source File: _base.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def minorticks_on(self): """ Display minor ticks on the axes. Displaying minor ticks may reduce performance; you may turn them off using `minorticks_off()` if drawing speed is a problem. """ for ax in (self.xaxis, self.yaxis): scale = ax.get_scale() if scale == 'log': s = ax._scale ax.set_minor_locator(mticker.LogLocator(s.base, s.subs)) elif scale == 'symlog': s = ax._scale ax.set_minor_locator( mticker.SymmetricalLogLocator(s._transform, s.subs)) else: ax.set_minor_locator(mticker.AutoMinorLocator())
Example #4
Source File: _base.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def minorticks_on(self): """ Display minor ticks on the axes. Displaying minor ticks may reduce performance; you may turn them off using `minorticks_off()` if drawing speed is a problem. """ for ax in (self.xaxis, self.yaxis): scale = ax.get_scale() if scale == 'log': s = ax._scale ax.set_minor_locator(mticker.LogLocator(s.base, s.subs)) elif scale == 'symlog': s = ax._scale ax.set_minor_locator( mticker.SymmetricalLogLocator(s._transform, s.subs)) else: ax.set_minor_locator(mticker.AutoMinorLocator())
Example #5
Source File: contour.py From neural-network-animation with MIT License | 6 votes |
def _autolev(self, z, N): """ Select contour levels to span the data. We need two more levels for filled contours than for line contours, because for the latter we need to specify the lower and upper boundary of each range. For example, a single contour boundary, say at z = 0, requires only one contour line, but two filled regions, and therefore three levels to provide boundaries for both regions. """ if self.locator is None: if self.logscale: self.locator = ticker.LogLocator() else: self.locator = ticker.MaxNLocator(N + 1) zmax = self.zmax zmin = self.zmin lev = self.locator.tick_values(zmin, zmax) self._auto = True if self.filled: return lev # For line contours, drop levels outside the data range. return lev[(lev > zmin) & (lev < zmax)]
Example #6
Source File: test_colorbar.py From coffeegrindsize with MIT License | 6 votes |
def test_colorbar_renorm(): x, y = np.ogrid[-4:4:31j, -4:4:31j] z = 120000*np.exp(-x**2 - y**2) fig, ax = plt.subplots() im = ax.imshow(z) cbar = fig.colorbar(im) norm = LogNorm(z.min(), z.max()) im.set_norm(norm) cbar.set_norm(norm) cbar.locator = LogLocator() cbar.formatter = LogFormatter() cbar.update_normal(im) assert np.isclose(cbar.vmin, z.min()) norm = LogNorm(z.min() * 1000, z.max() * 1000) im.set_norm(norm) cbar.set_norm(norm) cbar.update_normal(im) assert np.isclose(cbar.vmin, z.min() * 1000) assert np.isclose(cbar.vmax, z.max() * 1000)
Example #7
Source File: test_colorbar.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_colorbar_renorm(): x, y = np.ogrid[-4:4:31j, -4:4:31j] z = 120000*np.exp(-x**2 - y**2) fig, ax = plt.subplots() im = ax.imshow(z) cbar = fig.colorbar(im) norm = LogNorm(z.min(), z.max()) im.set_norm(norm) cbar.set_norm(norm) cbar.locator = LogLocator() cbar.formatter = LogFormatter() cbar.update_normal(im) assert np.isclose(cbar.vmin, z.min()) norm = LogNorm(z.min() * 1000, z.max() * 1000) im.set_norm(norm) cbar.set_norm(norm) cbar.update_normal(im) assert np.isclose(cbar.vmin, z.min() * 1000) assert np.isclose(cbar.vmax, z.max() * 1000)
Example #8
Source File: _base.py From CogAlg with MIT License | 6 votes |
def minorticks_on(self): """ Display minor ticks on the axes. Displaying minor ticks may reduce performance; you may turn them off using `minorticks_off()` if drawing speed is a problem. """ for ax in (self.xaxis, self.yaxis): scale = ax.get_scale() if scale == 'log': s = ax._scale ax.set_minor_locator(mticker.LogLocator(s.base, s.subs)) elif scale == 'symlog': s = ax._scale ax.set_minor_locator( mticker.SymmetricalLogLocator(s._transform, s.subs)) else: ax.set_minor_locator(mticker.AutoMinorLocator())
Example #9
Source File: colorbar.py From matplotlib-4-abaqus with MIT License | 6 votes |
def _select_locator(self, formatter): ''' select a suitable locator ''' if self.boundaries is None: if isinstance(self.norm, colors.NoNorm): nv = len(self._values) base = 1 + int(nv/10) locator = ticker.IndexLocator(base=base, offset=0) elif isinstance(self.norm, colors.BoundaryNorm): b = self.norm.boundaries locator = ticker.FixedLocator(b, nbins=10) elif isinstance(self.norm, colors.LogNorm): locator = ticker.LogLocator() else: locator = ticker.MaxNLocator(nbins=5) else: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b) #, nbins=10) self.cbar_axis.set_major_locator(locator)
Example #10
Source File: contour.py From matplotlib-4-abaqus with MIT License | 6 votes |
def _autolev(self, z, N): """ Select contour levels to span the data. We need two more levels for filled contours than for line contours, because for the latter we need to specify the lower and upper boundary of each range. For example, a single contour boundary, say at z = 0, requires only one contour line, but two filled regions, and therefore three levels to provide boundaries for both regions. """ if self.locator is None: if self.logscale: self.locator = ticker.LogLocator() else: self.locator = ticker.MaxNLocator(N + 1) zmax = self.zmax zmin = self.zmin lev = self.locator.tick_values(zmin, zmax) self._auto = True if self.filled: return lev # For line contours, drop levels outside the data range. return lev[(lev > zmin) & (lev < zmax)]
Example #11
Source File: colorbar.py From CogAlg with MIT License | 6 votes |
def _select_locator(self, formatter): ''' select a suitable locator ''' if self.boundaries is None: if isinstance(self.norm, colors.NoNorm): nv = len(self._values) base = 1 + int(nv/10) locator = ticker.IndexLocator(base=base, offset=0) elif isinstance(self.norm, colors.BoundaryNorm): b = self.norm.boundaries locator = ticker.FixedLocator(b, nbins=10) elif isinstance(self.norm, colors.LogNorm): locator = ticker.LogLocator() else: locator = ticker.MaxNLocator(nbins=5) else: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b) self.cbar_axis.set_major_locator(locator)
Example #12
Source File: _base.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def minorticks_on(self): """ Display minor ticks on the axes. Displaying minor ticks may reduce performance; you may turn them off using `minorticks_off()` if drawing speed is a problem. """ for ax in (self.xaxis, self.yaxis): scale = ax.get_scale() if scale == 'log': s = ax._scale ax.set_minor_locator(mticker.LogLocator(s.base, s.subs)) elif scale == 'symlog': s = ax._scale ax.set_minor_locator( mticker.SymmetricalLogLocator(s._transform, s.subs)) else: ax.set_minor_locator(mticker.AutoMinorLocator())
Example #13
Source File: plotter.py From ChainConsumer with MIT License | 6 votes |
def _plot_walk(self, ax, parameter, data, truth=None, extents=None, convolve=None, color=None, log_scale=False): # pragma: no cover if extents is not None: ax.set_ylim(extents) assert convolve is None or isinstance(convolve, int), "Convolve must be an integer pixel window width" x = np.arange(data.size) ax.set_xlim(0, x[-1]) ax.set_ylabel(parameter) if color is None: color = "#0345A1" ax.scatter(x, data, c=color, s=2, marker=".", edgecolors="none", alpha=0.5) max_ticks = self.parent.config["max_ticks"] if log_scale: ax.set_yscale("log") ax.yaxis.set_major_locator(LogLocator(numticks=max_ticks)) else: ax.yaxis.set_major_locator(MaxNLocator(max_ticks, prune="lower")) if convolve is not None: color2 = self.parent.color_finder.scale_colour(color, 0.5) filt = np.ones(convolve) / convolve filtered = np.convolve(data, filt, mode="same") ax.plot(x[:-1], filtered[:-1], ls=":", color=color2, alpha=1)
Example #14
Source File: colorbar.py From Computable with MIT License | 6 votes |
def _select_locator(self, formatter): ''' select a suitable locator ''' if self.boundaries is None: if isinstance(self.norm, colors.NoNorm): nv = len(self._values) base = 1 + int(nv/10) locator = ticker.IndexLocator(base=base, offset=0) elif isinstance(self.norm, colors.BoundaryNorm): b = self.norm.boundaries locator = ticker.FixedLocator(b, nbins=10) elif isinstance(self.norm, colors.LogNorm): locator = ticker.LogLocator() else: locator = ticker.MaxNLocator(nbins=5) else: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b) #, nbins=10) self.cbar_axis.set_major_locator(locator)
Example #15
Source File: colorbar.py From Computable with MIT License | 6 votes |
def _select_locator(self, formatter): ''' select a suitable locator ''' if self.boundaries is None: if isinstance(self.norm, colors.NoNorm): nv = len(self._values) base = 1 + int(nv/10) locator = ticker.IndexLocator(base=base, offset=0) elif isinstance(self.norm, colors.BoundaryNorm): b = self.norm.boundaries locator = ticker.FixedLocator(b, nbins=10) elif isinstance(self.norm, colors.LogNorm): locator = ticker.LogLocator() else: locator = ticker.MaxNLocator(nbins=5) else: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b) #, nbins=10) self.cbar_axis.set_major_locator(locator)
Example #16
Source File: contour.py From Computable with MIT License | 6 votes |
def _autolev(self, z, N): """ Select contour levels to span the data. We need two more levels for filled contours than for line contours, because for the latter we need to specify the lower and upper boundary of each range. For example, a single contour boundary, say at z = 0, requires only one contour line, but two filled regions, and therefore three levels to provide boundaries for both regions. """ if self.locator is None: if self.logscale: self.locator = ticker.LogLocator() else: self.locator = ticker.MaxNLocator(N + 1) zmax = self.zmax zmin = self.zmin lev = self.locator.tick_values(zmin, zmax) self._auto = True if self.filled: return lev # For line contours, drop levels outside the data range. return lev[(lev > zmin) & (lev < zmax)]
Example #17
Source File: basis_time.py From PyAbel with MIT License | 5 votes |
def plot(directory, xlim, ylim, linex): plt.figure(figsize=(6, 6), frameon=False) plt.xlabel('Image size ($n$, pixels)') plt.xscale('log') plt.xlim(xlim) plt.ylabel('Basis-set generation time (seconds)') plt.yscale('log') plt.ylim(ylim) plt.gca().yaxis.set_major_locator(LogLocator(base=10.0, numticks=12)) plt.grid(which='both', color='#EEEEEE') plt.grid(which='minor', linewidth=0.5) plt.tight_layout(pad=0.1) # quadratic guiding line plt.plot(xlim, ylim[0] * (np.array(xlim) / linex)**2, color='#AAAAAA', ls=':') # its annotation (must be done after all layout for correct rotation) p = plt.gca().transData.transform(np.array([[1, 1**2], [2, 2**2]])) plt.text(linex, ylim[0], '\n (quadratic scaling)', color='#AAAAAA', va='center', linespacing=2, rotation_mode='anchor', rotation=90 - np.degrees(np.arctan2(*(p[1] - p[0])))) # all timings for meth, color, pargs in transforms: try: times = np.loadtxt(directory + '/' + meth + '.dat', unpack=True) except OSError: continue if times.shape[0] < 3: continue n = times[0] t = times[2] * 1e-3 # in ms plt.plot(n, t, 'o-', label=meth, ms=5, color=color) plt.legend() # plt.show()
Example #18
Source File: _base.py From ImageFusion with MIT License | 5 votes |
def minorticks_on(self): 'Add autoscaling minor ticks to the axes.' for ax in (self.xaxis, self.yaxis): if ax.get_scale() == 'log': s = ax._scale ax.set_minor_locator(mticker.LogLocator(s.base, s.subs)) else: ax.set_minor_locator(mticker.AutoMinorLocator())
Example #19
Source File: test_ticker.py From ImageFusion with MIT License | 5 votes |
def test_LogLocator(): loc = mticker.LogLocator(numticks=5) assert_raises(ValueError, loc.tick_values, 0, 1000) test_value = np.array([1.00000000e-05, 1.00000000e-03, 1.00000000e-01, 1.00000000e+01, 1.00000000e+03, 1.00000000e+05, 1.00000000e+07, 1.000000000e+09]) assert_almost_equal(loc.tick_values(0.001, 1.1e5), test_value) loc = mticker.LogLocator(base=2) test_value = np.array([0.5, 1., 2., 4., 8., 16., 32., 64., 128., 256.]) assert_almost_equal(loc.tick_values(1, 100), test_value)
Example #20
Source File: element.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _set_axis_ticks(self, axis, ticks, log=False, rotation=0): """ Allows setting the ticks for a particular axis either with a tuple of ticks, a tick locator object, an integer number of ticks, a list of tuples containing positions and labels or a list of positions. Also supports enabling log ticking if an integer number of ticks is supplied and setting a rotation for the ticks. """ if isinstance(ticks, (list, tuple)) and all(isinstance(l, list) for l in ticks): axis.set_ticks(ticks[0]) axis.set_ticklabels(ticks[1]) elif isinstance(ticks, ticker.Locator): axis.set_major_locator(ticks) elif not ticks and ticks is not None: axis.set_ticks([]) elif isinstance(ticks, int): if log: locator = ticker.LogLocator(numticks=ticks, subs=range(1,10)) else: locator = ticker.MaxNLocator(ticks) axis.set_major_locator(locator) elif isinstance(ticks, (list, tuple)): labels = None if all(isinstance(t, tuple) for t in ticks): ticks, labels = zip(*ticks) axis.set_ticks(ticks) if labels: axis.set_ticklabels(labels) for tick in axis.get_ticklabels(): tick.set_rotation(rotation)
Example #21
Source File: planners_evaluation.py From rl-agents with MIT License | 5 votes |
def plot_all(data_file, directory, data_range): print("Reading data from {}".format(directory / data_file)) df = pd.read_csv(str(directory / data_file)) df = df[~df.agent.isin(['agent'])].apply(pd.to_numeric, errors='ignore') df = df.sort_values(by="agent") m = df.loc[df['simple_regret'] != np.inf, 'simple_regret'].max() df['simple_regret'].replace(np.inf, m, inplace=True) df = rename_df(df) if data_range: start, end = data_range.split(':') df = df[df["budget"].between(int(start), int(end))] print("Number of seeds found: {}".format(df.seed.nunique())) try: for field in [#"total_reward", "return", "length", "mean_return", "simple_regret"]: fig, ax = plt.subplots() ax.set(xscale="log") if field in ["simple_regret"]: ax.set_yscale("symlog", linthreshy=1e-2) sns.lineplot(x=rename("budget"), y=rename(field), ax=ax, hue="agent", data=df) ax.yaxis.set_minor_locator(LogLocator(base=10, subs="all")) ax.yaxis.grid(True, which='minor', linestyle='--') plt.legend(loc="lower left") field_path = directory / "{}.pdf".format(field) fig.savefig(field_path, bbox_inches='tight') field_path = directory / "{}.png".format(field) fig.savefig(field_path, bbox_inches='tight') print("Saving {} plot to {}".format(field, field_path)) except ValueError as e: print(e) custom_processing(df, directory)
Example #22
Source File: colorbar.py From coffeegrindsize with MIT License | 5 votes |
def __init__(self, colorbar, *args, **kwargs): """ _ColorbarLogLocator(colorbar, *args, **kwargs) This ticker needs to know the *colorbar* so that it can access its *vmin* and *vmax*. Otherwise it is the same as `~.ticker.LogLocator`. The ``*args`` and ``**kwargs`` are the same as `~.ticker.LogLocator`. """ self._colorbar = colorbar super().__init__(*args, **kwargs)
Example #23
Source File: test_ticker.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_sublabel(self): # test label locator fig, ax = plt.subplots() ax.set_xscale('log') ax.xaxis.set_major_locator(mticker.LogLocator(base=10, subs=[])) ax.xaxis.set_minor_locator(mticker.LogLocator(base=10, subs=np.arange(2, 10))) ax.xaxis.set_major_formatter(mticker.LogFormatter(labelOnlyBase=True)) ax.xaxis.set_minor_formatter(mticker.LogFormatter(labelOnlyBase=False)) # axis range above 3 decades, only bases are labeled ax.set_xlim(1, 1e4) fmt = ax.xaxis.get_major_formatter() fmt.set_locs(ax.xaxis.get_majorticklocs()) show_major_labels = [fmt(x) != '' for x in ax.xaxis.get_majorticklocs()] assert np.all(show_major_labels) self._sub_labels(ax.xaxis, subs=[]) # For the next two, if the numdec threshold in LogFormatter.set_locs # were 3, then the label sub would be 3 for 2-3 decades and (2,5) # for 1-2 decades. With a threshold of 1, subs are not labeled. # axis range at 2 to 3 decades ax.set_xlim(1, 800) self._sub_labels(ax.xaxis, subs=[]) # axis range at 1 to 2 decades ax.set_xlim(1, 80) self._sub_labels(ax.xaxis, subs=[]) # axis range at 0.4 to 1 decades, label subs 2, 3, 4, 6 ax.set_xlim(1, 8) self._sub_labels(ax.xaxis, subs=[2, 3, 4, 6]) # axis range at 0 to 0.4 decades, label all ax.set_xlim(0.5, 0.9) self._sub_labels(ax.xaxis, subs=np.arange(2, 10, dtype=int))
Example #24
Source File: colorbar.py From coffeegrindsize with MIT License | 5 votes |
def _ticker(self, locator, formatter): ''' Return the sequence of ticks (colorbar data locations), ticklabels (strings), and the corresponding offset string. ''' if isinstance(self.norm, colors.NoNorm) and self.boundaries is None: intv = self._values[0], self._values[-1] else: intv = self.vmin, self.vmax locator.create_dummy_axis(minpos=intv[0]) formatter.create_dummy_axis(minpos=intv[0]) locator.set_view_interval(*intv) locator.set_data_interval(*intv) formatter.set_view_interval(*intv) formatter.set_data_interval(*intv) b = np.array(locator()) if isinstance(locator, ticker.LogLocator): eps = 1e-10 b = b[(b <= intv[1] * (1 + eps)) & (b >= intv[0] * (1 - eps))] else: eps = (intv[1] - intv[0]) * 1e-10 b = b[(b <= intv[1] + eps) & (b >= intv[0] - eps)] self._manual_tick_data_values = b ticks = self._locate(b) formatter.set_locs(b) ticklabels = [formatter(t, i) for i, t in enumerate(b)] offset_string = formatter.get_offset() return ticks, ticklabels, offset_string
Example #25
Source File: test_ticker.py From coffeegrindsize with MIT License | 5 votes |
def test_basic(self): loc = mticker.LogLocator(numticks=5) with pytest.raises(ValueError): loc.tick_values(0, 1000) test_value = np.array([1.00000000e-05, 1.00000000e-03, 1.00000000e-01, 1.00000000e+01, 1.00000000e+03, 1.00000000e+05, 1.00000000e+07, 1.000000000e+09]) assert_almost_equal(loc.tick_values(0.001, 1.1e5), test_value) loc = mticker.LogLocator(base=2) test_value = np.array([0.5, 1., 2., 4., 8., 16., 32., 64., 128., 256.]) assert_almost_equal(loc.tick_values(1, 100), test_value)
Example #26
Source File: test_ticker.py From coffeegrindsize with MIT License | 5 votes |
def test_set_params(self): """ Create log locator with default value, base=10.0, subs=[1.0], numdecs=4, numticks=15 and change it to something else. See if change was successful. Should not raise exception. """ loc = mticker.LogLocator() loc.set_params(numticks=7, numdecs=8, subs=[2.0], base=4) assert loc.numticks == 7 assert loc.numdecs == 8 assert loc._base == 4 assert list(loc._subs) == [2.0]
Example #27
Source File: test_ticker.py From coffeegrindsize with MIT License | 5 votes |
def test_majformatter_type(): fig, ax = plt.subplots() with pytest.raises(TypeError): ax.xaxis.set_major_formatter(matplotlib.ticker.LogLocator())
Example #28
Source File: test_ticker.py From coffeegrindsize with MIT License | 5 votes |
def test_minformatter_type(): fig, ax = plt.subplots() with pytest.raises(TypeError): ax.xaxis.set_minor_formatter(matplotlib.ticker.LogLocator())
Example #29
Source File: colorbar.py From CogAlg with MIT License | 5 votes |
def __init__(self, colorbar, *args, **kwargs): """ _ColorbarLogLocator(colorbar, *args, **kwargs) This ticker needs to know the *colorbar* so that it can access its *vmin* and *vmax*. Otherwise it is the same as `~.ticker.LogLocator`. The ``*args`` and ``**kwargs`` are the same as `~.ticker.LogLocator`. """ self._colorbar = colorbar super().__init__(*args, **kwargs)
Example #30
Source File: colorbar.py From CogAlg with MIT License | 5 votes |
def _ticker(self, locator, formatter): ''' Return the sequence of ticks (colorbar data locations), ticklabels (strings), and the corresponding offset string. ''' if isinstance(self.norm, colors.NoNorm) and self.boundaries is None: intv = self._values[0], self._values[-1] else: intv = self.vmin, self.vmax locator.create_dummy_axis(minpos=intv[0]) formatter.create_dummy_axis(minpos=intv[0]) locator.set_view_interval(*intv) locator.set_data_interval(*intv) formatter.set_view_interval(*intv) formatter.set_data_interval(*intv) b = np.array(locator()) if isinstance(locator, ticker.LogLocator): eps = 1e-10 b = b[(b <= intv[1] * (1 + eps)) & (b >= intv[0] * (1 - eps))] else: eps = (intv[1] - intv[0]) * 1e-10 b = b[(b <= intv[1] + eps) & (b >= intv[0] - eps)] self._manual_tick_data_values = b ticks = self._locate(b) ticklabels = formatter.format_ticks(b) offset_string = formatter.get_offset() return ticks, ticklabels, offset_string