Skip to content

Commit 0ea7930

Browse files
authored
Merge pull request #291 from nschloe/axis-styles
Axis styles
2 parents 41a4d4e + ab84e6d commit 0ea7930

File tree

54 files changed

+326
-319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+326
-319
lines changed

matplotlib2tikz/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
__email__ = "[email protected]"
55
__copyright__ = u"Copyright (c) 2010-2019, {} <{}>".format(__author__, __email__)
66
__license__ = "License :: OSI Approved :: MIT License"
7-
__version__ = "0.7.2"
7+
__version__ = "0.7.3"
88
__status__ = "Development Status :: 5 - Production/Stable"

matplotlib2tikz/axes.py

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def __init__(self, data, obj):
1313
"""
1414
self.content = []
1515

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.
1818
self.is_colorbar = _is_colorbar_heuristic(obj)
1919
if self.is_colorbar:
2020
return
@@ -51,8 +51,7 @@ def __init__(self, data, obj):
5151
self.axis_options.append(u"ylabel={{{}}}".format(ylabel))
5252

5353
# 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.
5655
ff = data["float format"]
5756
xlim = sorted(list(obj.get_xlim()))
5857
self.axis_options.append(("xmin=" + ff + ", xmax=" + ff).format(*xlim))
@@ -71,6 +70,12 @@ def __init__(self, data, obj):
7170
"log basis y={{{}}}".format(_try_f2i(obj.yaxis._scale.base))
7271
)
7372

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.
7479
if not obj.get_axisbelow():
7580
self.axis_options.append("axis on top")
7681

@@ -108,12 +113,7 @@ def __init__(self, data, obj):
108113
self.axis_options.append("axis line style={{{}}}".format(col))
109114

110115
# 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()
117117

118118
data, col, _ = color.mpl_color2xcolor(data, bgcolor)
119119
if col != "white":
@@ -201,13 +201,31 @@ def _ticks(self, data, obj):
201201
)
202202
)
203203

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+
204222
# Find tick direction
205223
# For new matplotlib versions, we could replace the direction getter by
206224
# `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.
211229
x_tick_dirs = [tick._tickdir for tick in obj.xaxis.get_major_ticks()]
212230
y_tick_dirs = [tick._tickdir for tick in obj.yaxis.get_major_ticks()]
213231
if x_tick_dirs or y_tick_dirs:
@@ -256,9 +274,8 @@ def _ticks(self, data, obj):
256274

257275
def _grid(self, obj, data):
258276
# 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.
262279
if obj.xaxis._gridOnMajor:
263280
self.axis_options.append("xmajorgrids")
264281
if obj.xaxis._gridOnMinor:
@@ -516,15 +533,14 @@ def _get_tick_position(obj, axes_obj):
516533

517534

518535
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
521537
necessary axis options for the given configuration.
522538
"""
523539
axis_options = []
524540
pgfplots_ticks = []
525541
pgfplots_ticklabels = []
526542
is_label_required = False
527-
for (tick, ticklabel) in zip(ticks, ticklabels):
543+
for tick, ticklabel in zip(ticks, ticklabels):
528544
pgfplots_ticks.append(tick)
529545
# store the label anyway
530546
label = ticklabel.get_text()
@@ -533,17 +549,17 @@ def _get_ticks(data, xy, ticks, ticklabels):
533549
pgfplots_ticklabels.append(label)
534550
else:
535551
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.
538554
if label:
539555
try:
540556
label_float = float(label.replace(u"\N{MINUS SIGN}", "-"))
541557
is_label_required = is_label_required or (label and label_float != tick)
542558
except ValueError:
543559
is_label_required = True
544560

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.
547563
if data["strict"] or is_label_required:
548564
if pgfplots_ticks:
549565
ff = data["float format"]

test/create_tex

Lines changed: 0 additions & 170 deletions
This file was deleted.

test/phash

Lines changed: 0 additions & 30 deletions
This file was deleted.

test/test_annotate_reference.tex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
tick pos=left,
66
x grid style={white!69.01960784313725!black},
77
xmin=-1, xmax=5,
8+
xtick style={color=black},
89
y grid style={white!69.01960784313725!black},
9-
ymin=-4, ymax=3
10+
ymin=-4, ymax=3,
11+
ytick style={color=black}
1012
]
1113
\addplot [semithick, blue]
1214
table {%

test/test_arrows_reference.tex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
tick pos=left,
88
x grid style={white!69.01960784313725!black},
99
xmin=0, xmax=8,
10+
xtick style={color=black},
1011
y grid style={white!69.01960784313725!black},
11-
ymin=0, ymax=7.5
12+
ymin=0, ymax=7.5,
13+
ytick style={color=black}
1214
]
1315
\draw[fill=color0,draw opacity=0] (axis cs:3.2,6.8) circle (0.2);
1416
\draw[fill=color0,draw opacity=0] (axis cs:3.2,5.8) circle (0.2);

test/test_axvline_reference.tex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
tick pos=left,
88
x grid style={white!69.01960784313725!black},
99
xmin=-2.64601320556273, xmax=2.17933396216965,
10+
xtick style={color=black},
1011
y grid style={white!69.01960784313725!black},
11-
ymin=-1, ymax=1
12+
ymin=-1, ymax=1,
13+
ytick style={color=black}
1214
]
1315
\draw[fill=color0,draw opacity=0] (axis cs:-2.42667924339307,0) rectangle (axis cs:-2.29074205071007,1);
1416
\draw[fill=color0,draw opacity=0] (axis cs:-2.29074205071007,0) rectangle (axis cs:-2.15480485802706,0);

test/test_barchart_errorbars_reference.tex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
tick pos=left,
66
x grid style={white!69.01960784313725!black},
77
xmin=-0.5125, xmax=2.5125,
8+
xtick style={color=black},
89
y grid style={white!69.01960784313725!black},
9-
ymin=0, ymax=5.355
10+
ymin=0, ymax=5.355,
11+
ytick style={color=black}
1012
]
1113
\draw[fill=blue,draw opacity=0] (axis cs:-0.375,0) rectangle (axis cs:-0.125,1);
1214
\draw[fill=blue,draw opacity=0] (axis cs:0.625,0) rectangle (axis cs:0.875,2);

0 commit comments

Comments
 (0)