Skip to content

Commit b564b88

Browse files
authored
Merge pull request #511 from frutti93/transfer-axis-label-colors
Transfer axis label colors
2 parents 162ad22 + a02fbf1 commit b564b88

5 files changed

+26
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ build/
1010
*.egg-info/
1111
.pytest_cache/
1212
.tox/
13+
mytikz.tex
14+
test.tex

src/tikzplotlib/_axes.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,30 @@ def __init__(self, data, obj): # noqa: C901
4949
xlabel = obj.get_xlabel()
5050
if xlabel:
5151
xlabel = _common_texification(xlabel)
52-
self.axis_options.append(f"xlabel={{{xlabel}}}")
52+
53+
labelcolor = obj.xaxis.label.get_c()
54+
55+
if labelcolor != "black":
56+
data, col, _ = _color.mpl_color2xcolor(data, labelcolor)
57+
self.axis_options.append(f"xlabel=\\textcolor{{{col}}}{{{xlabel}}}")
58+
else:
59+
self.axis_options.append(f"xlabel={{{xlabel}}}")
60+
5361
xrotation = obj.xaxis.get_label().get_rotation()
5462
if xrotation != 0:
5563
self.axis_options.append(f"xlabel style={{rotate={xrotation - 90}}}")
64+
5665
ylabel = obj.get_ylabel()
5766
if ylabel:
5867
ylabel = _common_texification(ylabel)
59-
self.axis_options.append(f"ylabel={{{ylabel}}}")
68+
69+
labelcolor = obj.yaxis.label.get_c()
70+
if labelcolor != "black":
71+
data, col, _ = _color.mpl_color2xcolor(data, labelcolor)
72+
self.axis_options.append(f"ylabel=\\textcolor{{{col}}}{{{ylabel}}}")
73+
else:
74+
self.axis_options.append(f"ylabel={{{ylabel}}}")
75+
6076
yrotation = obj.yaxis.get_label().get_rotation()
6177
if yrotation != 90:
6278
self.axis_options.append(f"ylabel style={{rotate={yrotation - 90}}}")

tests/test_basic_sin_reference.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
tick pos=left,
2121
title={Simple plot \(\displaystyle \frac{\alpha}{2}\)},
2222
x grid style={white},
23-
xlabel={time(s)},
23+
xlabel=\textcolor{white!33.333333!black}{time(s)},
2424
xmajorgrids,
2525
xmin=-0.095, xmax=1.995,
2626
xtick style={color=white!33.333333!black},
2727
y grid style={white},
28-
ylabel={Voltage (mV)},
28+
ylabel=\textcolor{white!33.333333!black}{Voltage (mV)},
2929
ymajorgrids,
3030
ymin=-1.1, ymax=1.1,
3131
ytick style={color=white!33.333333!black}

tests/test_externalize_tables_reference.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
tick pos=left,
1111
title={Simple plot \(\displaystyle \frac{\alpha}{2}\)},
1212
x grid style={white},
13-
xlabel={time(s)},
13+
xlabel=\textcolor{white!33.333333!black}{time(s)},
1414
xmajorgrids,
1515
xmin=-0.095, xmax=1.995,
1616
xtick style={color=white!33.333333!black},
1717
y grid style={white},
18-
ylabel={Voltage (mV)},
18+
ylabel=\textcolor{white!33.333333!black}{Voltage (mV)},
1919
ymajorgrids,
2020
ymin=-1.1, ymax=1.1,
2121
ytick style={color=white!33.333333!black}

tests/test_line_color_marker_reference.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
tick pos=left,
1111
title={Simple plot \(\displaystyle \frac{\alpha}{2}\)},
1212
x grid style={white},
13-
xlabel={time(s)},
13+
xlabel=\textcolor{white!33.333333!black}{time(s)},
1414
xmajorgrids,
1515
xmin=-0.095, xmax=1.995,
1616
xtick style={color=white!33.333333!black},
1717
y grid style={white},
18-
ylabel={Voltage (mV)},
18+
ylabel=\textcolor{white!33.333333!black}{Voltage (mV)},
1919
ymajorgrids,
2020
ymin=-1.1, ymax=1.1,
2121
ytick style={color=white!33.333333!black}

0 commit comments

Comments
 (0)