Пример #1
0
    def set_scatter_ticks(self, ax: plt.Axes, minor_ticks=False):
        """Intelligently creates major and minor ticks for a square scatter plot while avoiding crowding"""

        # Get tick locations corresponding to the current view limits
        major_locs, ax_min, ax_max = self.get_fixed_majorticklocs(ax.viewLim.bounds)

        ax.xaxis.set_major_locator(tix.FixedLocator(major_locs))
        ax.yaxis.set_major_locator(tix.FixedLocator(major_locs))

        if len(self.dge_scatter_tick_cache):
            self.restore_ticks(ax, "both")
            return

        for axis in [ax.xaxis, ax.yaxis]:
            # Only display every nth major tick label
            ticks_displayed, last_idx = self.every_nth_label(axis, 3)

            if minor_ticks:
                axis.set_minor_locator(tix.LogLocator(
                    base=2.0,
                    numticks=self.get_min_LogLocator_numticks(axis),
                    subs=np.log2(np.linspace(2 ** 2, 2 ** 4, 10))[:-1]))

            min_tick = 2 ** (np.log2(ax_min)+1)
            max_tick = major_locs[last_idx]
            self.set_tick_bounds(axis, min_tick=min_tick, max_tick=max_tick, minor=minor_ticks)
            self.cache_ticks(axis, axis.__name__)
Пример #2
0
 def set_my_locators_and_formatters(self, axis):
     # choose the default locator and additional parameters
     if isinstance(axis, matplotlib.axis.XAxis):
         axis.set_major_locator(MaxNLocator())
     elif isinstance(axis, matplotlib.axis.YAxis):
         axis.set_major_locator(MaxNLocator())
     # copy&paste from the original method
     axis.set_major_formatter(ScalarFormatter())
     axis.set_minor_locator(NullLocator())
     axis.set_minor_formatter(NullFormatter())