@@ -13,8 +13,8 @@ def __init__(self, data, obj):
13
13
"""
14
14
self .content = []
15
15
16
- # Are we dealing with an axis that hosts a colorbar? Skip then, those
17
- # are treated implicitily by the associated axis.
16
+ # Are we dealing with an axis that hosts a colorbar? Skip then, those are
17
+ # treated implicitily by the associated axis.
18
18
self .is_colorbar = _is_colorbar_heuristic (obj )
19
19
if self .is_colorbar :
20
20
return
@@ -51,8 +51,7 @@ def __init__(self, data, obj):
51
51
self .axis_options .append (u"ylabel={{{}}}" .format (ylabel ))
52
52
53
53
# Axes limits.
54
- # Sort the limits so make sure that the smaller of the two is actually
55
- # *min.
54
+ # Sort the limits so make sure that the smaller of the two is actually *min.
56
55
ff = data ["float format" ]
57
56
xlim = sorted (list (obj .get_xlim ()))
58
57
self .axis_options .append (("xmin=" + ff + ", xmax=" + ff ).format (* xlim ))
@@ -71,6 +70,12 @@ def __init__(self, data, obj):
71
70
"log basis y={{{}}}" .format (_try_f2i (obj .yaxis ._scale .base ))
72
71
)
73
72
73
+ # Possible values for get_axisbelow():
74
+ # True (zorder = 0.5): Ticks and gridlines are below all Artists.
75
+ # 'line' (zorder = 1.5): Ticks and gridlines are above patches (e.g.
76
+ # rectangles) but still below lines / markers.
77
+ # False (zorder = 2.5): Ticks and gridlines are above patches and lines /
78
+ # markers.
74
79
if not obj .get_axisbelow ():
75
80
self .axis_options .append ("axis on top" )
76
81
@@ -108,12 +113,7 @@ def __init__(self, data, obj):
108
113
self .axis_options .append ("axis line style={{{}}}" .format (col ))
109
114
110
115
# background color
111
- try :
112
- # mpl 2.*
113
- bgcolor = obj .get_facecolor ()
114
- except AttributeError :
115
- # mpl 1.*
116
- bgcolor = obj .get_axis_bgcolor ()
116
+ bgcolor = obj .get_facecolor ()
117
117
118
118
data , col , _ = color .mpl_color2xcolor (data , bgcolor )
119
119
if col != "white" :
@@ -201,13 +201,31 @@ def _ticks(self, data, obj):
201
201
)
202
202
)
203
203
204
+ try :
205
+ l0 = obj .get_xticklines ()[0 ]
206
+ except IndexError :
207
+ pass
208
+ else :
209
+ c0 = l0 .get_color ()
210
+ data , xtickcolor , _ = color .mpl_color2xcolor (data , c0 )
211
+ self .axis_options .append ("xtick style={{color={}}}" .format (xtickcolor ))
212
+
213
+ try :
214
+ l0 = obj .get_yticklines ()[0 ]
215
+ except IndexError :
216
+ pass
217
+ else :
218
+ c0 = l0 .get_color ()
219
+ data , ytickcolor , _ = color .mpl_color2xcolor (data , c0 )
220
+ self .axis_options .append ("ytick style={{color={}}}" .format (ytickcolor ))
221
+
204
222
# Find tick direction
205
223
# For new matplotlib versions, we could replace the direction getter by
206
224
# `get_ticks_direction()`, see
207
- # <https://github.com/matplotlib/matplotlib/pull/5290>.
208
- # Unfortunately, _tickdir doesn't seem to be quite accurate. See
209
- # <https://github.com/matplotlib/matplotlib/issues/5311>.
210
- # For now, just take the first tick direction of each of the axes.
225
+ # <https://github.com/matplotlib/matplotlib/pull/5290>. Unfortunately, _tickdir
226
+ # doesn't seem to be quite accurate. See
227
+ # <https://github.com/matplotlib/matplotlib/issues/5311>. For now, just take
228
+ # the first tick direction of each of the axes.
211
229
x_tick_dirs = [tick ._tickdir for tick in obj .xaxis .get_major_ticks ()]
212
230
y_tick_dirs = [tick ._tickdir for tick in obj .yaxis .get_major_ticks ()]
213
231
if x_tick_dirs or y_tick_dirs :
@@ -256,9 +274,8 @@ def _ticks(self, data, obj):
256
274
257
275
def _grid (self , obj , data ):
258
276
# Don't use get_{x,y}gridlines for gridlines; see discussion on
259
- # <http://sourceforge.net/p/matplotlib/mailman/message/25169234/>
260
- # Coordinate of the lines are entirely meaningless, but styles
261
- # (colors,...) are respected.
277
+ # <http://sourceforge.net/p/matplotlib/mailman/message/25169234/> Coordinate of
278
+ # the lines are entirely meaningless, but styles (colors,...) are respected.
262
279
if obj .xaxis ._gridOnMajor :
263
280
self .axis_options .append ("xmajorgrids" )
264
281
if obj .xaxis ._gridOnMinor :
@@ -516,15 +533,14 @@ def _get_tick_position(obj, axes_obj):
516
533
517
534
518
535
def _get_ticks (data , xy , ticks , ticklabels ):
519
- """
520
- Gets a {'x','y'}, a number of ticks and ticks labels, and returns the
536
+ """Gets a {'x','y'}, a number of ticks and ticks labels, and returns the
521
537
necessary axis options for the given configuration.
522
538
"""
523
539
axis_options = []
524
540
pgfplots_ticks = []
525
541
pgfplots_ticklabels = []
526
542
is_label_required = False
527
- for ( tick , ticklabel ) in zip (ticks , ticklabels ):
543
+ for tick , ticklabel in zip (ticks , ticklabels ):
528
544
pgfplots_ticks .append (tick )
529
545
# store the label anyway
530
546
label = ticklabel .get_text ()
@@ -533,17 +549,17 @@ def _get_ticks(data, xy, ticks, ticklabels):
533
549
pgfplots_ticklabels .append (label )
534
550
else :
535
551
is_label_required = True
536
- # Check if the label is necessary. If one of the labels is, then all
537
- # of them must appear in the TikZ plot.
552
+ # Check if the label is necessary. If one of the labels is, then all of them
553
+ # must appear in the TikZ plot.
538
554
if label :
539
555
try :
540
556
label_float = float (label .replace (u"\N{MINUS SIGN} " , "-" ))
541
557
is_label_required = is_label_required or (label and label_float != tick )
542
558
except ValueError :
543
559
is_label_required = True
544
560
545
- # Leave the ticks to PGFPlots if not in STRICT mode and if there are no
546
- # explicit labels.
561
+ # Leave the ticks to PGFPlots if not in STRICT mode and if there are no explicit
562
+ # labels.
547
563
if data ["strict" ] or is_label_required :
548
564
if pgfplots_ticks :
549
565
ff = data ["float format" ]
0 commit comments