Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 82a986a

Browse files
committed
Remove the changes that are now in #10193 (gridline property handling)
1 parent 2371be7 commit 82a986a

File tree

2 files changed

+58
-74
lines changed

2 files changed

+58
-74
lines changed

lib/matplotlib/axis.py

Lines changed: 55 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@
2828

2929
GRIDLINE_INTERPOLATION_STEPS = 180
3030

31-
# This list is being used for compatibility with Axes.grid, which
32-
# allows all Line2D kwargs.
33-
_line_AI = artist.ArtistInspector(mlines.Line2D)
34-
_line_param_names = _line_AI.get_setters()
35-
_line_param_aliases = [list(d.keys())[0] for d in _line_AI.aliasd.values()]
36-
_gridline_param_names = ['grid_' + name
37-
for name in _line_param_names + _line_param_aliases]
38-
3931

4032
class Tick(artist.Artist):
4133
"""
@@ -94,11 +86,6 @@ def __init__(self, axes, loc, label,
9486
label2On=False,
9587
major=True,
9688
labelrotation=0,
97-
grid_color=None,
98-
grid_linestyle=None,
99-
grid_linewidth=None,
100-
grid_alpha=None,
101-
**kw # Other Line2D kwargs applied to gridlines.
10289
):
10390
"""
10491
bbox is the Bound2D bounding box in display coords of the Axes
@@ -166,17 +153,6 @@ def __init__(self, axes, loc, label,
166153
zorder = mlines.Line2D.zorder
167154
self._zorder = zorder
168155

169-
self._grid_color = (rcParams['grid.color']
170-
if grid_color is None else grid_color)
171-
self._grid_linestyle = (rcParams['grid.linestyle']
172-
if grid_linestyle is None else grid_linestyle)
173-
self._grid_linewidth = (rcParams['grid.linewidth']
174-
if grid_linewidth is None else grid_linewidth)
175-
self._grid_alpha = (rcParams['grid.alpha']
176-
if grid_alpha is None else grid_alpha)
177-
178-
self._grid_kw = {k[5:]: v for k, v in kw.items()}
179-
180156
self.apply_tickdir(tickdir)
181157

182158
self.tick1line = self._get_tick1line()
@@ -392,14 +368,6 @@ def _apply_params(self, **kw):
392368
v = getattr(self.label1, 'get_' + k)()
393369
setattr(self, '_label' + k, v)
394370

395-
grid_list = [k for k in six.iteritems(kw)
396-
if k[0] in _gridline_param_names]
397-
if grid_list:
398-
grid_kw = {k[5:]: v for k, v in grid_list}
399-
self.gridline.set(**grid_kw)
400-
for k, v in six.iteritems(grid_kw):
401-
setattr(self, '_grid_' + k, v)
402-
403371
def update_position(self, loc):
404372
'Set the location of tick in data coords with scalar *loc*'
405373
raise NotImplementedError('Derived must override')
@@ -501,12 +469,11 @@ def _get_gridline(self):
501469
'Get the default line2D instance'
502470
# x in data coords, y in axes coords
503471
l = mlines.Line2D(xdata=(0.0, 0.0), ydata=(0, 1.0),
504-
color=self._grid_color,
505-
linestyle=self._grid_linestyle,
506-
linewidth=self._grid_linewidth,
507-
alpha=self._grid_alpha,
508-
markersize=0,
509-
**self._grid_kw)
472+
color=rcParams['grid.color'],
473+
linestyle=rcParams['grid.linestyle'],
474+
linewidth=rcParams['grid.linewidth'],
475+
alpha=rcParams['grid.alpha'],
476+
markersize=0)
510477
l.set_transform(self.axes.get_xaxis_transform(which='grid'))
511478
l.get_path()._interpolation_steps = GRIDLINE_INTERPOLATION_STEPS
512479
self._set_artist_props(l)
@@ -625,12 +592,12 @@ def _get_gridline(self):
625592
'Get the default line2D instance'
626593
# x in axes coords, y in data coords
627594
l = mlines.Line2D(xdata=(0, 1), ydata=(0, 0),
628-
color=self._grid_color,
629-
linestyle=self._grid_linestyle,
630-
linewidth=self._grid_linewidth,
631-
alpha=self._grid_alpha,
632-
markersize=0,
633-
**self._grid_kw)
595+
color=rcParams['grid.color'],
596+
linestyle=rcParams['grid.linestyle'],
597+
linewidth=rcParams['grid.linewidth'],
598+
alpha=rcParams['grid.alpha'],
599+
markersize=0)
600+
634601
l.set_transform(self.axes.get_yaxis_transform(which='grid'))
635602
l.get_path()._interpolation_steps = GRIDLINE_INTERPOLATION_STEPS
636603
self._set_artist_props(l)
@@ -683,6 +650,13 @@ def __init__(self, axes, pickradius=15):
683650
artist.Artist.__init__(self)
684651
self.set_figure(axes.figure)
685652

653+
# Keep track of setting to the default value, this allows use to know
654+
# if any of the following values is explicitly set by the user, so as
655+
# to not overwrite their settings with any of our 'auto' settings.
656+
self.isDefault_majloc = True
657+
self.isDefault_minloc = True
658+
self.isDefault_majfmt = True
659+
self.isDefault_minfmt = True
686660
self.isDefault_label = True
687661

688662
self.axes = axes
@@ -771,10 +745,22 @@ def get_children(self):
771745

772746
def cla(self):
773747
'clear the current axis'
748+
self.set_major_locator(mticker.AutoLocator())
749+
self.set_major_formatter(mticker.ScalarFormatter())
750+
self.set_minor_locator(mticker.NullLocator())
751+
self.set_minor_formatter(mticker.NullFormatter())
774752

775-
self.label.set_text('') # self.set_label_text would change isDefault_
753+
self.set_label_text('')
754+
self._set_artist_props(self.label)
776755

777-
self._set_scale('linear')
756+
# Keep track of setting to the default value, this allows use to know
757+
# if any of the following values is explicitly set by the user, so as
758+
# to not overwrite their settings with any of our 'auto' settings.
759+
self.isDefault_majloc = True
760+
self.isDefault_minloc = True
761+
self.isDefault_majfmt = True
762+
self.isDefault_minfmt = True
763+
self.isDefault_label = True
778764

779765
# Clear the callback registry for this axis, or it may "leak"
780766
self.callbacks = cbook.CallbackRegistry()
@@ -785,6 +771,9 @@ def cla(self):
785771
self._gridOnMinor = (rcParams['axes.grid'] and
786772
rcParams['axes.grid.which'] in ('both', 'minor'))
787773

774+
self.label.set_text('')
775+
self._set_artist_props(self.label)
776+
788777
self.reset_ticks()
789778

790779
self.converter = None
@@ -793,11 +782,9 @@ def cla(self):
793782
self.stale = True
794783

795784
def reset_ticks(self):
796-
"""
797-
Re-initialize the major and minor Tick lists.
798-
799-
Each list starts with a single fresh Tick.
800-
"""
785+
# build a few default ticks; grow as necessary later; only
786+
# define 1 so properties set on ticks will be copied as they
787+
# grow
801788
del self.majorTicks[:]
802789
del self.minorTicks[:]
803790

@@ -806,11 +793,6 @@ def reset_ticks(self):
806793
self._lastNumMajorTicks = 1
807794
self._lastNumMinorTicks = 1
808795

809-
try:
810-
self.set_clip_path(self.axes.patch)
811-
except AttributeError:
812-
pass
813-
814796
def set_tick_params(self, which='major', reset=False, **kw):
815797
"""
816798
Set appearance parameters for ticks and ticklabels.
@@ -828,7 +810,6 @@ def set_tick_params(self, which='major', reset=False, **kw):
828810
if reset:
829811
d.clear()
830812
d.update(kwtrans)
831-
832813
if reset:
833814
self.reset_ticks()
834815
else:
@@ -852,8 +833,7 @@ def _translate_tick_kw(kw, to_init_kw=True):
852833
kwkeys1 = ['length', 'direction', 'left', 'bottom', 'right', 'top',
853834
'labelleft', 'labelbottom', 'labelright', 'labeltop',
854835
'labelrotation']
855-
kwkeys2 = _gridline_param_names
856-
kwkeys = kwkeys0 + kwkeys1 + kwkeys2
836+
kwkeys = kwkeys0 + kwkeys1
857837
kwtrans = dict()
858838
if to_init_kw:
859839
if 'length' in kw:
@@ -995,7 +975,7 @@ def _update_ticks(self, renderer):
995975
"""
996976

997977
interval = self.get_view_interval()
998-
tick_tups = list(self.iter_ticks()) # iter_ticks calls the locator
978+
tick_tups = list(self.iter_ticks())
999979
if self._smart_bounds and tick_tups:
1000980
# handle inverted limits
1001981
view_low, view_high = sorted(interval)
@@ -1421,21 +1401,30 @@ def grid(self, b=None, which='major', **kwargs):
14211401
if len(kwargs):
14221402
b = True
14231403
which = which.lower()
1424-
gridkw = {'grid_' + item[0]: item[1] for item in kwargs.items()}
14251404
if which in ['minor', 'both']:
14261405
if b is None:
14271406
self._gridOnMinor = not self._gridOnMinor
14281407
else:
14291408
self._gridOnMinor = b
1430-
self.set_tick_params(which='minor', gridOn=self._gridOnMinor,
1431-
**gridkw)
1409+
for tick in self.minorTicks: # don't use get_ticks here!
1410+
if tick is None:
1411+
continue
1412+
tick.gridOn = self._gridOnMinor
1413+
if len(kwargs):
1414+
tick.gridline.update(kwargs)
1415+
self._minor_tick_kw['gridOn'] = self._gridOnMinor
14321416
if which in ['major', 'both']:
14331417
if b is None:
14341418
self._gridOnMajor = not self._gridOnMajor
14351419
else:
14361420
self._gridOnMajor = b
1437-
self.set_tick_params(which='major', gridOn=self._gridOnMajor,
1438-
**gridkw)
1421+
for tick in self.majorTicks: # don't use get_ticks here!
1422+
if tick is None:
1423+
continue
1424+
tick.gridOn = self._gridOnMajor
1425+
if len(kwargs):
1426+
tick.gridline.update(kwargs)
1427+
self._major_tick_kw['gridOn'] = self._gridOnMajor
14391428
self.stale = True
14401429

14411430
def update_units(self, data):
@@ -1465,11 +1454,11 @@ def _update_axisinfo(self):
14651454
check the axis converter for the stored units to see if the
14661455
axis info needs to be updated
14671456
"""
1457+
14681458
if self.converter is None:
14691459
return
14701460

14711461
info = self.converter.axisinfo(self.units, self)
1472-
14731462
if info is None:
14741463
return
14751464
if info.majloc is not None and \

lib/matplotlib/scale.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
import numpy as np
77
from numpy import ma
88

9-
from matplotlib import cbook, docstring, rcParams
9+
from matplotlib import cbook, docstring
1010
from matplotlib.ticker import (
1111
NullFormatter, ScalarFormatter, LogFormatterSciNotation, LogitFormatter,
12-
NullLocator, LogLocator, AutoLocator, AutoMinorLocator,
13-
SymmetricalLogLocator, LogitLocator)
12+
NullLocator, LogLocator, AutoLocator, SymmetricalLogLocator, LogitLocator)
1413
from matplotlib.transforms import Transform, IdentityTransform
1514

1615

@@ -72,12 +71,8 @@ def set_default_locators_and_formatters(self, axis):
7271
"""
7372
axis.set_major_locator(AutoLocator())
7473
axis.set_major_formatter(ScalarFormatter())
74+
axis.set_minor_locator(NullLocator())
7575
axis.set_minor_formatter(NullFormatter())
76-
# update the minor locator for x and y axis based on rcParams
77-
if rcParams['xtick.minor.visible']:
78-
axis.set_minor_locator(AutoMinorLocator())
79-
else:
80-
axis.set_minor_locator(NullLocator())
8176

8277
def get_transform(self):
8378
"""

0 commit comments

Comments
 (0)