Skip to content

Commit 0d5d36d

Browse files
committed
sort colors by key
1 parent ccb46cd commit 0d5d36d

8 files changed

+54
-39
lines changed

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ install_requires =
4141
matplotlib >= 1.4.0
4242
numpy
4343
Pillow
44+
webcolors
4445
python_requires = >=3.7
4546

4647
[options.packages.find]

src/tikzplotlib/_save.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,12 @@ def _tex_comment(comment):
271271

272272
def _get_color_definitions(data):
273273
"""Returns the list of custom color definitions for the TikZ file."""
274-
ff = data["float format"]
274+
# sort by key
275+
sorted_keys = sorted(data["custom colors"].keys(), key=lambda x: x.lower())
276+
d = {key: data["custom colors"][key] for key in sorted_keys}
275277
return [
276-
f"\\definecolor{{{name}}}{{rgb}}{{{rgb[0]:{ff}},{rgb[1]:{ff}},{rgb[2]:{ff}}}}"
277-
for name, rgb in data["custom colors"].items()
278+
f"\\definecolor{{{name}}}{{{space}}}{{{val}}}"
279+
for name, (space, val) in d.items()
278280
]
279281

280282

tests/test_barchart_legend_reference.tex

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
\begin{tikzpicture}
22

3+
\definecolor{gray069}{gray}{0.6901960784313725}
4+
\definecolor{green01270}{RGB}{0,127,0}
5+
\definecolor{gray080}{gray}{0.8}
6+
37
\begin{axis}[
48
legend cell align={left},
5-
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, draw=white!80!black},
9+
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, draw=gray080},
610
tick align=outside,
711
tick pos=left,
8-
x grid style={white!69.019608!black},
12+
x grid style={gray069},
913
xmin=-0.5125, xmax=2.5125,
1014
xtick style={color=black},
11-
y grid style={white!69.019608!black},
15+
y grid style={gray069},
1216
ymin=0, ymax=5.25,
1317
ytick style={color=black}
1418
]
@@ -18,12 +22,12 @@
1822

1923
\draw[draw=none,fill=blue] (axis cs:0.625,0) rectangle (axis cs:0.875,2);
2024
\draw[draw=none,fill=blue] (axis cs:1.625,0) rectangle (axis cs:1.875,3);
21-
\draw[draw=none,fill=green!50!black] (axis cs:-0.125,0) rectangle (axis cs:0.125,3);
25+
\draw[draw=none,fill=green01270] (axis cs:-0.125,0) rectangle (axis cs:0.125,3);
2226
\addlegendimage{ybar,ybar legend,draw=none,fill=green!50!black}
2327
\addlegendentry{Data 2}
2428

25-
\draw[draw=none,fill=green!50!black] (axis cs:0.875,0) rectangle (axis cs:1.125,2);
26-
\draw[draw=none,fill=green!50!black] (axis cs:1.875,0) rectangle (axis cs:2.125,4);
29+
\draw[draw=none,fill=green01270] (axis cs:0.875,0) rectangle (axis cs:1.125,2);
30+
\draw[draw=none,fill=green01270] (axis cs:1.875,0) rectangle (axis cs:2.125,4);
2731
\draw[draw=none,fill=red] (axis cs:0.125,0) rectangle (axis cs:0.375,5);
2832
\addlegendimage{ybar,ybar legend,draw=none,fill=red}
2933
\addlegendentry{Data 3}

tests/test_cleanfigure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ def test_xlog_2(self):
602602
num_lines_raw = raw.count("\n")
603603
num_lines_clean = clean.count("\n")
604604
assert num_lines_raw - num_lines_clean == 51
605-
assert num_lines_clean == 71
605+
assert num_lines_clean == 72
606606
plt.close("all")
607607

608608
def test_loglog_2(self):

tests/test_context_reference.tex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
\starttikzpicture
22

3+
\definecolor{gray069}{gray}{0.6901960784313725}
4+
35
\startaxis[
46
tick align=outside,
57
tick pos=left,
6-
x grid style={white!69.019608!black},
8+
x grid style={gray069},
79
xmin=0, xmax=1,
810
xtick style={color=black},
9-
y grid style={white!69.019608!black},
11+
y grid style={gray069},
1012
ymin=0, ymax=1,
1113
ytick style={color=black}
1214
]

tests/test_fancy_colorbar_reference.tex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
\begin{tikzpicture}
22

3+
\definecolor{gray069}{gray}{0.6901960784313725}
4+
35
\begin{axis}[
46
colorbar,
57
colorbar style={ylabel={}},
@@ -8,11 +10,11 @@
810
point meta min=0,
911
tick align=outside,
1012
tick pos=left,
11-
x grid style={white!69.019608!black},
13+
x grid style={gray069},
1214
xmin=-0.5, xmax=2.5,
1315
xtick style={color=black},
1416
y dir=reverse,
15-
y grid style={white!69.019608!black},
17+
y grid style={gray069},
1618
ymin=-0.5, ymax=2.5,
1719
ytick style={color=black}
1820
]

tests/test_heat_reference.tex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
\begin{tikzpicture}
22

3+
\definecolor{gray069}{gray}{0.6901960784313725}
4+
35
\begin{axis}[
46
colorbar,
57
colorbar style={ylabel={}},
@@ -8,10 +10,10 @@
810
point meta min=-100,
911
tick align=outside,
1012
tick pos=left,
11-
x grid style={white!69.019608!black},
13+
x grid style={gray069},
1214
xmin=-10, xmax=10,
1315
xtick style={color=black},
14-
y grid style={white!69.019608!black},
16+
y grid style={gray069},
1517
ymin=-10, ymax=10,
1618
ytick style={color=black}
1719
]

tests/test_text_overlay_reference.tex

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
\begin{tikzpicture}
22

3-
\definecolor{color0}{rgb}{0.12156863,0.46666667,0.70588235}
4-
\definecolor{color1}{rgb}{1,0.8,0.8}
5-
\definecolor{color2}{rgb}{1,0.5,0.5}
3+
\definecolor{gray069}{gray}{0.6901960784313725}
4+
\definecolor{gray080}{gray}{0.8}
5+
\definecolor{pink255204204}{RGB}{255,204,204}
6+
\definecolor{salmon255127127}{RGB}{255,127,127}
7+
\definecolor{steelblue31119180}{RGB}{31,119,180}
68

79
\begin{axis}[
810
legend cell align={left},
@@ -12,18 +14,18 @@
1214
text opacity=1,
1315
at={(0.03,0.97)},
1416
anchor=north west,
15-
draw=white!80!black
17+
draw=gray080
1618
},
1719
tick align=outside,
1820
tick pos=left,
19-
x grid style={white!69.019608!black},
21+
x grid style={gray069},
2022
xmin=-0.25, xmax=5.25,
2123
xtick style={color=black},
22-
y grid style={white!69.019608!black},
24+
y grid style={gray069},
2325
ymin=-1.25, ymax=26.25,
2426
ytick style={color=black}
2527
]
26-
\addplot [semithick, color0]
28+
\addplot [semithick, steelblue31119180]
2729
table {%
2830
0 0
2931
0.10204082 0.010412328
@@ -79,8 +81,8 @@
7981
\addlegendentry{a graph}
8082
\draw (axis cs:1,5) node[
8183
scale=2.5,
82-
fill=color1,
83-
draw=color2,
84+
fill=pink255204204,
85+
draw=salmon255127127,
8486
line width=0.4pt,
8587
inner sep=2pt,
8688
rounded corners,
@@ -91,16 +93,16 @@
9193
]{\itshape test1};
9294
\draw (axis cs:3,6) node[
9395
scale=2.5,
94-
fill=color1,
95-
draw=color2,
96+
fill=pink255204204,
97+
draw=salmon255127127,
9698
line width=0.4pt,
9799
inner sep=3pt,
98100
text=blue,
99101
rotate=330.0
100102
]{\bfseries test2};
101103
\draw (axis cs:4,8) node[
102-
fill=color1,
103-
draw=color2,
104+
fill=pink255204204,
105+
draw=salmon255127127,
104106
line width=0.4pt,
105107
inner sep=3pt,
106108
single arrow,
@@ -109,8 +111,8 @@
109111
rotate=90.0
110112
]{\bfseries test3};
111113
\draw (axis cs:4,16) node[
112-
fill=color1,
113-
draw=color2,
114+
fill=pink255204204,
115+
draw=salmon255127127,
114116
line width=0.4pt,
115117
inner sep=3pt,
116118
single arrow,
@@ -120,26 +122,26 @@
120122
rotate=90.0
121123
]{\bfseries test4};
122124
\draw (axis cs:2,18) node[
123-
fill=color1,
124-
draw=color2,
125+
fill=pink255204204,
126+
draw=salmon255127127,
125127
line width=0.4pt,
126128
inner sep=3pt,
127129
double arrow,
128130
text=blue,
129131
rotate=0.0
130132
]{test5};
131133
\draw (axis cs:1,20) node[
132-
fill=color1,
133-
draw=color2,
134+
fill=pink255204204,
135+
draw=salmon255127127,
134136
line width=0.4pt,
135137
inner sep=3pt,
136138
circle,
137139
text=blue,
138140
rotate=0.0
139141
]{test6};
140142
\draw (axis cs:3,23) node[
141-
fill=color1,
142-
draw=color2,
143+
fill=pink255204204,
144+
draw=salmon255127127,
143145
line width=0.4pt,
144146
inner sep=3pt,
145147
decorate,
@@ -148,8 +150,8 @@
148150
rotate=0.0
149151
]{test7};
150152
\draw (axis cs:3,20) node[
151-
fill=color1,
152-
draw=color2,
153+
fill=pink255204204,
154+
draw=salmon255127127,
153155
line width=0.4pt,
154156
inner sep=3pt,
155157
decorate,

0 commit comments

Comments
 (0)