Python matplotlib.ticker.IndexLocator() Examples
The following are 21
code examples of matplotlib.ticker.IndexLocator().
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 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 #2
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 #3
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 #4
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 #5
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 #6
Source File: colorbar.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def _get_ticker_locator_formatter(self): """ This code looks at the norm being used by the colorbar and decides what locator and formatter to use. If ``locator`` has already been set by hand, it just returns ``self.locator, self.formatter``. """ locator = self.locator formatter = self.formatter if locator is None: 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 = _ColorbarLogLocator(self) elif isinstance(self.norm, colors.SymLogNorm): # The subs setting here should be replaced # by logic in the locator. locator = ticker.SymmetricalLogLocator( subs=np.arange(1, 10), linthresh=self.norm.linthresh, base=10) else: if mpl.rcParams['_internal.classic_mode']: locator = ticker.MaxNLocator() else: locator = _ColorbarAutoLocator(self) else: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b, nbins=10) _log.debug('locator: %r', locator) return locator, formatter
Example #7
Source File: colorbar.py From GraphicDesignPatternByPython 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 #8
Source File: test_ticker.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_set_params(self): """ Create index locator with 3 base, 4 offset. and change it to something else. See if change was successful. Should not exception. """ index = mticker.IndexLocator(base=3, offset=4) index.set_params(base=7, offset=7) assert index._base == 7 assert index.offset == 7
Example #9
Source File: figure.py From CapsLayer with Apache License 2.0 | 5 votes |
def plot_activation(matrix, step, save_to=None): save_to = os.path.join(".", "activations") if save_to is None else save_to os.makedirs(save_to, exist_ok=True) if len(matrix.shape) != 2: raise ValueError('Input "matrix" should have 2 rank, but it is',str(len(matrix.shape))) num_label = matrix.shape[1] - 1 matrix = matrix[matrix[:, num_label].argsort()] fig, axes = plt.subplots(ncols=1, nrows=num_label, figsize=(15,12)) fig.suptitle("The probability of entity presence (step %s)"%str(step), fontsize=20) fig.tight_layout() for i, ax in enumerate(axes.flatten()): idx = num_label - (i + 1) ax.spines['top'].set_color('none') ax.spines['bottom'].set_color('none') ax.set_ylim(0, 1.05) ax.set_ylabel("Capsule " + str(idx)) ax.yaxis.set_major_locator(ticker.NullLocator()) if idx > 0: ax.xaxis.set_major_locator(ticker.NullLocator()) else: ax.xaxis.set_major_locator(ticker.IndexLocator(base=500,offset=0)) ax.set_xlabel("Sample index ") ax.plot(matrix[:,idx]) ax_prime = ax.twinx() ax_prime.spines['top'].set_color('none') ax_prime.spines['bottom'].set_color('none') plt.subplots_adjust(hspace=0.2, left=0.05, right=0.95, bottom=0.05, top=.95) plt.savefig(os.path.join(save_to, "activation_%s.png" % str(step))) plt.close()
Example #10
Source File: test_ticker.py From coffeegrindsize with MIT License | 5 votes |
def test_set_params(self): """ Create index locator with 3 base, 4 offset. and change it to something else. See if change was successful. Should not exception. """ index = mticker.IndexLocator(base=3, offset=4) index.set_params(base=7, offset=7) assert index._base == 7 assert index.offset == 7
Example #11
Source File: colorbar.py From coffeegrindsize with MIT License | 5 votes |
def _get_ticker_locator_formatter(self): """ This code looks at the norm being used by the colorbar and decides what locator and formatter to use. If ``locator`` has already been set by hand, it just returns ``self.locator, self.formatter``. """ locator = self.locator formatter = self.formatter if locator is None: 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 = _ColorbarLogLocator(self) elif isinstance(self.norm, colors.SymLogNorm): # The subs setting here should be replaced # by logic in the locator. locator = ticker.SymmetricalLogLocator( subs=np.arange(1, 10), linthresh=self.norm.linthresh, base=10) else: if mpl.rcParams['_internal.classic_mode']: locator = ticker.MaxNLocator() else: locator = _ColorbarAutoLocator(self) else: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b, nbins=10) _log.debug('locator: %r', locator) return locator, formatter
Example #12
Source File: test_ticker.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_set_params(self): """ Create index locator with 3 base, 4 offset. and change it to something else. See if change was successful. Should not exception. """ index = mticker.IndexLocator(base=3, offset=4) index.set_params(base=7, offset=7) assert index._base == 7 assert index.offset == 7
Example #13
Source File: colorbar.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _get_ticker_locator_formatter(self): """ This code looks at the norm being used by the colorbar and decides what locator and formatter to use. If ``locator`` has already been set by hand, it just returns ``self.locator, self.formatter``. """ locator = self.locator formatter = self.formatter if locator is None: 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 = _ColorbarLogLocator(self) elif isinstance(self.norm, colors.SymLogNorm): # The subs setting here should be replaced # by logic in the locator. locator = ticker.SymmetricalLogLocator( subs=np.arange(1, 10), linthresh=self.norm.linthresh, base=10) else: if mpl.rcParams['_internal.classic_mode']: locator = ticker.MaxNLocator() else: locator = _ColorbarAutoLocator(self) else: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b, nbins=10) _log.debug('locator: %r', locator) return locator, formatter
Example #14
Source File: evans_test.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def axisinfo(unit, axis): 'return the Foo AxisInfo' if unit == 1.0 or unit == 2.0: return units.AxisInfo( majloc=ticker.IndexLocator(8, 0), majfmt=ticker.FormatStrFormatter("VAL: %s"), label='foo', ) else: return None
Example #15
Source File: colorbar.py From ImageFusion with MIT License | 4 votes |
def _ticker(self): ''' Return the sequence of ticks (colorbar data locations), ticklabels (strings), and the corresponding offset string. ''' locator = self.locator formatter = self.formatter if locator is None: 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() else: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b, nbins=10) if isinstance(self.norm, colors.NoNorm): 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()) ticks = self._locate(b) inrange = (ticks > -0.001) & (ticks < 1.001) ticks = ticks[inrange] b = b[inrange] 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 #16
Source File: colorbar.py From neural-network-animation with MIT License | 4 votes |
def _ticker(self): ''' Return the sequence of ticks (colorbar data locations), ticklabels (strings), and the corresponding offset string. ''' locator = self.locator formatter = self.formatter if locator is None: 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() else: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b, nbins=10) if isinstance(self.norm, colors.NoNorm): 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()) ticks = self._locate(b) inrange = (ticks > -0.001) & (ticks < 1.001) ticks = ticks[inrange] b = b[inrange] 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 #17
Source File: colorbar.py From matplotlib-4-abaqus with MIT License | 4 votes |
def _ticker(self): ''' Return two sequences: ticks (colorbar data locations) and ticklabels (strings). ''' locator = self.locator formatter = self.formatter if locator is None: 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() else: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b, nbins=10) if isinstance(self.norm, colors.NoNorm): 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()) ticks = self._locate(b) inrange = (ticks > -0.001) & (ticks < 1.001) ticks = ticks[inrange] b = b[inrange] 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 #18
Source File: colorbar.py From CogAlg with MIT License | 4 votes |
def _get_ticker_locator_formatter(self): """ This code looks at the norm being used by the colorbar and decides what locator and formatter to use. If ``locator`` has already been set by hand, it just returns ``self.locator, self.formatter``. """ locator = self.locator formatter = self.formatter if locator is None: 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 = _ColorbarLogLocator(self) elif isinstance(self.norm, colors.SymLogNorm): # The subs setting here should be replaced # by logic in the locator. locator = ticker.SymmetricalLogLocator( subs=np.arange(1, 10), linthresh=self.norm.linthresh, base=10) else: if mpl.rcParams['_internal.classic_mode']: locator = ticker.MaxNLocator() else: locator = _ColorbarAutoLocator(self) else: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b, nbins=10) if formatter is None: if isinstance(self.norm, colors.LogNorm): formatter = ticker.LogFormatterSciNotation() elif isinstance(self.norm, colors.SymLogNorm): formatter = ticker.LogFormatterSciNotation( linthresh=self.norm.linthresh) else: formatter = ticker.ScalarFormatter() else: formatter = self.formatter self.locator = locator self.formatter = formatter _log.debug('locator: %r', locator) return locator, formatter
Example #19
Source File: colorbar.py From Mastering-Elasticsearch-7.0 with MIT License | 4 votes |
def _get_ticker_locator_formatter(self): """ This code looks at the norm being used by the colorbar and decides what locator and formatter to use. If ``locator`` has already been set by hand, it just returns ``self.locator, self.formatter``. """ locator = self.locator formatter = self.formatter if locator is None: 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 = _ColorbarLogLocator(self) elif isinstance(self.norm, colors.SymLogNorm): # The subs setting here should be replaced # by logic in the locator. locator = ticker.SymmetricalLogLocator( subs=np.arange(1, 10), linthresh=self.norm.linthresh, base=10) else: if mpl.rcParams['_internal.classic_mode']: locator = ticker.MaxNLocator() else: locator = _ColorbarAutoLocator(self) else: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b, nbins=10) if formatter is None: if isinstance(self.norm, colors.LogNorm): formatter = ticker.LogFormatterSciNotation() elif isinstance(self.norm, colors.SymLogNorm): formatter = ticker.LogFormatterSciNotation( linthresh=self.norm.linthresh) else: formatter = ticker.ScalarFormatter() else: formatter = self.formatter self.locator = locator self.formatter = formatter _log.debug('locator: %r', locator) return locator, formatter
Example #20
Source File: colorbar.py From twitter-stock-recommendation with MIT License | 4 votes |
def _ticker(self): ''' Return the sequence of ticks (colorbar data locations), ticklabels (strings), and the corresponding offset string. ''' locator = self.locator formatter = self.formatter if locator is None: 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(subs='all') elif isinstance(self.norm, colors.SymLogNorm): # The subs setting here should be replaced # by logic in the locator. locator = ticker.SymmetricalLogLocator( subs=np.arange(1, 10), linthresh=self.norm.linthresh, base=10) else: if mpl.rcParams['_internal.classic_mode']: locator = ticker.MaxNLocator() else: locator = ticker.AutoLocator() else: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b, nbins=10) 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._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 #21
Source File: colorbar.py From Computable with MIT License | 4 votes |
def _ticker(self): ''' Return two sequences: ticks (colorbar data locations) and ticklabels (strings). ''' locator = self.locator formatter = self.formatter if locator is None: 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() else: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b, nbins=10) if isinstance(self.norm, colors.NoNorm): 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()) ticks = self._locate(b) inrange = (ticks > -0.001) & (ticks < 1.001) ticks = ticks[inrange] b = b[inrange] formatter.set_locs(b) ticklabels = [formatter(t, i) for i, t in enumerate(b)] offset_string = formatter.get_offset() return ticks, ticklabels, offset_string