Skip to content

Tick maximum #5723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed doc/_static/logo2.png
Binary file not shown.
520 changes: 520 additions & 0 deletions doc/_static/logo2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/_templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ <h3>We're updating the default styles for Matplotlib 2.0</h3>

<div style="background-color: white; text-align: left; padding: 10px 10px 15px 15px">
<a href="{{ pathto('index') }}"><img src="{{
pathto("_static/logo2.png", 1) }}" border="0" alt="matplotlib"/></a>
pathto("_static/logo2.svg", 1) }}" width="540px" border="0" alt="matplotlib"/></a>
</div>

{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion doc/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def all():
os.unlink(link)
else:
raise RuntimeError("doc/{0} should be a directory or symlink -- it"
" isn't")
" isn't".format(link))
if not os.path.exists(link):
if hasattr(os, 'symlink'):
os.symlink(target, link)
Expand Down
12 changes: 12 additions & 0 deletions doc/mpl_toolkits/axes_grid/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@
axes_divider_api.rst
axes_grid_api.rst
axis_artist_api.rst


#######################################
The Matplotlib axes_grid1 Toolkit API
#######################################

:Release: |version|
:Date: |today|

.. toctree::

inset_locator_api.rst
7 changes: 7 additions & 0 deletions doc/mpl_toolkits/axes_grid/api/inset_locator_api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:mod:`mpl_toolkits.axes_grid1.inset_locator`
============================================

.. automodule:: mpl_toolkits.axes_grid1.inset_locator
:members:
:undoc-members:
:show-inheritance:
16 changes: 8 additions & 8 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2923,9 +2923,9 @@ def xywhere(xs, ys, mask):
barcols.append(self.hlines(yo, lo, ro, **lines_kw))
rightup, yup = xywhere(right, y, xlolims & everymask)
if self.xaxis_inverted():
marker = mlines.CARETLEFT
marker = mlines.CARETLEFTBASE
else:
marker = mlines.CARETRIGHT
marker = mlines.CARETRIGHTBASE
caplines.extend(
self.plot(rightup, yup, ls='None', marker=marker,
**plot_kw))
Expand All @@ -2939,9 +2939,9 @@ def xywhere(xs, ys, mask):
barcols.append(self.hlines(yo, lo, ro, **lines_kw))
leftlo, ylo = xywhere(left, y, xuplims & everymask)
if self.xaxis_inverted():
marker = mlines.CARETRIGHT
marker = mlines.CARETRIGHTBASE
else:
marker = mlines.CARETLEFT
marker = mlines.CARETLEFTBASE
caplines.extend(
self.plot(leftlo, ylo, ls='None', marker=marker,
**plot_kw))
Expand Down Expand Up @@ -2987,9 +2987,9 @@ def xywhere(xs, ys, mask):
barcols.append(self.vlines(xo, lo, uo, **lines_kw))
xup, upperup = xywhere(x, upper, lolims & everymask)
if self.yaxis_inverted():
marker = mlines.CARETDOWN
marker = mlines.CARETDOWNBASE
else:
marker = mlines.CARETUP
marker = mlines.CARETUPBASE
caplines.extend(
self.plot(xup, upperup, ls='None', marker=marker,
**plot_kw))
Expand All @@ -3003,9 +3003,9 @@ def xywhere(xs, ys, mask):
barcols.append(self.vlines(xo, lo, uo, **lines_kw))
xlo, lowerlo = xywhere(x, lower, uplims & everymask)
if self.yaxis_inverted():
marker = mlines.CARETUP
marker = mlines.CARETUPBASE
else:
marker = mlines.CARETDOWN
marker = mlines.CARETDOWNBASE
caplines.extend(
self.plot(xlo, lowerlo, ls='None', marker=marker,
**plot_kw))
Expand Down
6 changes: 5 additions & 1 deletion lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,11 @@ def get_window_extent(self, *args, **kwargs):
get the axes bounding box in display space; *args* and
*kwargs* are empty
"""
return self.bbox
bbox = self.bbox
x_pad = self.xaxis.get_tick_padding()
y_pad = self.yaxis.get_tick_padding()
return mtransforms.Bbox([[bbox.x0 - x_pad, bbox.y0 - y_pad],
[bbox.x1 + x_pad, bbox.y1 + y_pad]])

def _init_axis(self):
"move this out of __init__ because non-separable axes don't use it"
Expand Down
64 changes: 58 additions & 6 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,20 @@ def apply_tickdir(self, tickdir):
"""
pass

def get_tickdir(self):
return self._tickdir

def get_tick_padding(self):
"""
Get the length of the tick outside of the axes.
"""
padding = {
'in': 0.0,
'inout': 0.5,
'out': 1.0
}
return self._size * padding[self._tickdir]

def get_children(self):
children = [self.tick1line, self.tick2line,
self.gridline, self.label1, self.label2]
Expand Down Expand Up @@ -349,13 +363,11 @@ def apply_tickdir(self, tickdir):

if self._tickdir == 'in':
self._tickmarkers = (mlines.TICKUP, mlines.TICKDOWN)
self._pad = self._base_pad
elif self._tickdir == 'inout':
self._tickmarkers = ('|', '|')
self._pad = self._base_pad + self._size / 2.
else:
self._tickmarkers = (mlines.TICKDOWN, mlines.TICKUP)
self._pad = self._base_pad + self._size
self._pad = self._base_pad + self.get_tick_padding()
self.stale = True

def _get_text1(self):
Expand Down Expand Up @@ -485,13 +497,11 @@ def apply_tickdir(self, tickdir):

if self._tickdir == 'in':
self._tickmarkers = (mlines.TICKRIGHT, mlines.TICKLEFT)
self._pad = self._base_pad
elif self._tickdir == 'inout':
self._tickmarkers = ('_', '_')
self._pad = self._base_pad + self._size / 2.
else:
self._tickmarkers = (mlines.TICKLEFT, mlines.TICKRIGHT)
self._pad = self._base_pad + self._size
self._pad = self._base_pad + self.get_tick_padding()
self.stale = True

# how far from the y axis line the right of the ticklabel are
Expand Down Expand Up @@ -654,6 +664,7 @@ def __init__(self, axes, pickradius=15):
# Initialize here for testing; later add API
self._major_tick_kw = dict()
self._minor_tick_kw = dict()
self._tick_space = None

self.cla()
self._set_scale('linear')
Expand Down Expand Up @@ -785,6 +796,7 @@ def set_tick_params(self, which='major', reset=False, **kw):
for tick in self.minorTicks:
tick._apply_params(**self._minor_tick_kw)
self.stale = True
self._tick_space = None

@staticmethod
def _translate_tick_kw(kw, to_init_kw=True):
Expand Down Expand Up @@ -1095,6 +1107,16 @@ def get_tightbbox(self, renderer):
else:
return None

def get_tick_padding(self):
values = []
if len(self.majorTicks):
values.append(self.majorTicks[0].get_tick_padding())
if len(self.minorTicks):
values.append(self.minorTicks[0].get_tick_padding())
if len(values):
return max(values)
return 0.0

@allow_rasterization
def draw(self, renderer, *args, **kwargs):
'Draw the axis lines, grid lines, tick lines and labels'
Expand Down Expand Up @@ -1643,6 +1665,13 @@ def axis_date(self, tz=None):
tz = pytz.timezone(tz)
self.update_units(datetime.datetime(2009, 1, 1, 0, 0, 0, 0, tz))

def get_tick_space(self):
"""
Return the estimated number of ticks that can fit on the axis.
"""
# Must be overridden in the subclass
raise NotImplementedError()


class XAxis(Axis):
__name__ = 'xaxis'
Expand Down Expand Up @@ -1966,6 +1995,18 @@ def set_default_intervals(self):
self.axes.viewLim.intervalx = xmin, xmax
self.stale = True

def get_tick_space(self):
if self._tick_space is None:
ends = self.axes.transAxes.transform([[0, 0], [1, 0]])
length = ((ends[1][0] - ends[0][0]) / self.axes.figure.dpi) * 72.0
tick = self._get_tick(True)
# There is a heuristic here that the aspect ratio of tick text
# is no more than 3:1
size = tick.label1.get_size() * 3
size *= np.cos(np.deg2rad(tick.label1.get_rotation()))
self._tick_space = np.floor(length / size)
return self._tick_space


class YAxis(Axis):
__name__ = 'yaxis'
Expand Down Expand Up @@ -2296,3 +2337,14 @@ def set_default_intervals(self):
if not viewMutated:
self.axes.viewLim.intervaly = ymin, ymax
self.stale = True

def get_tick_space(self):
if self._tick_space is None:
ends = self.axes.transAxes.transform([[0, 0], [0, 1]])
length = ((ends[1][1] - ends[0][1]) / self.axes.figure.dpi) * 72.0
tick = self._get_tick(True)
# Having a spacing of at least 2 just looks good.
size = tick.label1.get_size() * 2.0
size *= np.cos(np.deg2rad(tick.label1.get_rotation()))
self._tick_space = np.floor(length / size)
return self._tick_space
1 change: 1 addition & 0 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ def notify_axes_change(fig):
if self.toolbar is not None:
self.toolbar.update()
self.canvas.figure.add_axobserver(notify_axes_change)
self.window.raise_()

@QtCore.Slot()
def _show_message(self, s):
Expand Down
10 changes: 9 additions & 1 deletion lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -1656,7 +1656,7 @@ class Grouper(object):
False

"""
def __init__(self, init=[]):
def __init__(self, init=()):
mapping = self._mapping = {}
for x in init:
mapping[ref(x)] = [ref(x)]
Expand Down Expand Up @@ -1708,6 +1708,14 @@ def joined(self, a, b):
except KeyError:
return False

def remove(self, a):
self.clean()

mapping = self._mapping
seta = mapping.pop(ref(a), None)
if seta is not None:
seta.remove(ref(a))

def __iter__(self):
"""
Iterate over each of the disjoint sets as a list.
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def _ticker(self):
else:
b = self._boundaries[self._inside]
locator = ticker.FixedLocator(b, nbins=10)
if isinstance(self.norm, colors.NoNorm):
if isinstance(self.norm, colors.NoNorm) and self.boundaries is None:
intv = self._values[0], self._values[-1]
else:
intv = self.vmin, self.vmax
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ def __call__(self, x, pos=None):
elif six.callable(fmt):
result = fmt(x, pos)
else:
raise TypeError('Unexpected type passed to {!r}.'.formatter(self))
raise TypeError('Unexpected type passed to {0!r}.'.format(self))

return result

Expand Down
30 changes: 28 additions & 2 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ def add_axes(self, *args, **kwargs):

self._axstack.add(key, a)
self.sca(a)
a._remove_method = lambda ax: self.delaxes(ax)
a._remove_method = self.__remove_ax
self.stale = True
a.stale_callback = _stale_figure_callback
return a
Expand Down Expand Up @@ -1006,11 +1006,37 @@ def add_subplot(self, *args, **kwargs):

self._axstack.add(key, a)
self.sca(a)
a._remove_method = lambda ax: self.delaxes(ax)
a._remove_method = self.__remove_ax
self.stale = True
a.stale_callback = _stale_figure_callback
return a

def __remove_ax(self, ax):
def _reset_loc_form(axis):
axis.set_major_formatter(axis.get_major_formatter())
axis.set_major_locator(axis.get_major_locator())
axis.set_minor_formatter(axis.get_minor_formatter())
axis.set_minor_locator(axis.get_minor_locator())

def _break_share_link(ax, grouper):
siblings = grouper.get_siblings(ax)
if len(siblings) > 1:
grouper.remove(ax)
for last_ax in siblings:
if ax is last_ax:
continue
return last_ax
return None

self.delaxes(ax)
last_ax = _break_share_link(ax, ax._shared_y_axes)
if last_ax is not None:
_reset_loc_form(last_ax.yaxis)

last_ax = _break_share_link(ax, ax._shared_x_axes)
if last_ax is not None:
_reset_loc_form(last_ax.xaxis)

def clf(self, keep_observers=False):
"""
Clear the figure.
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
# Imported here for backward compatibility, even though they don't
# really belong.
from matplotlib.markers import TICKLEFT, TICKRIGHT, TICKUP, TICKDOWN
from matplotlib.markers import CARETLEFT, CARETRIGHT, CARETUP, CARETDOWN
from matplotlib.markers import (
CARETLEFT, CARETRIGHT, CARETUP, CARETDOWN,
CARETLEFTBASE, CARETRIGHTBASE, CARETUPBASE, CARETDOWNBASE)


def segment_hits(cx, cy, x, y, radius):
Expand Down
Loading