Skip to content

Commit faa2375

Browse files
committed
colors: don't handle gray separately
1 parent 0d5d36d commit faa2375

File tree

4 files changed

+42
-35
lines changed

4 files changed

+42
-35
lines changed

src/tikzplotlib/_color.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,22 @@ def mpl_color2xcolor(data, matplotlib_color):
6666
if all(my_col[:3] == rgb):
6767
return data, name, my_col
6868

69-
if np.all(my_col[0] == my_col[:3]):
70-
# gray
71-
# my_col[0] = 0.70123112 -> gray070
72-
name = f"gray{int(100 * my_col[0]):03d}"
73-
if name not in data["custom colors"]:
74-
data["custom colors"][name] = ("gray", str(my_col[0]))
75-
return data, name, my_col
69+
# Don't handle gray colors separately. They can be specified in xcolor as
70+
#
71+
# {gray}{0.6901960784313725}
72+
#
73+
# but this float representation hides the fact that this is actually an
74+
# RGB255 integer value, 176.
7675

7776
# convert to RGB255
7877
rgb255 = np.array(my_col[:3] * 255, dtype=int)
7978

8079
name, diff = _get_closest_colour_name(rgb255)
8180
if diff > 0:
82-
name = f"{name}{rgb255[0]}{rgb255[1]}{rgb255[2]}"
81+
if np.all(my_col[0] == my_col[:3]):
82+
name = f"{name}{rgb255[0]}"
83+
else:
84+
name = f"{name}{rgb255[0]}{rgb255[1]}{rgb255[2]}"
8385
data["custom colors"][name] = ("RGB", ",".join([str(val) for val in rgb255]))
8486

8587
return data, name, my_col

tests/test_legends_reference.tex

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

3+
\definecolor{gray069}{gray}{0.6901960784313725}
4+
\definecolor{gray080}{gray}{0.8}
5+
\definecolor{green01270}{RGB}{0,127,0}
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,
812
title={Masked line demo},
913
unbounded coords=jump,
10-
x grid style={white!69.019608!black},
14+
x grid style={gray069},
1115
xmin=-0.3, xmax=6.3,
1216
xtick style={color=black},
13-
y grid style={white!69.019608!black},
17+
y grid style={gray069},
1418
ymin=-1.0959515, ymax=1.0993605,
1519
ytick style={color=black}
1620
]
@@ -34,7 +38,7 @@
3438
6 -0.2794155
3539
};
3640
\addlegendentry{No mask}
37-
\addplot [thick, green!50!black]
41+
\addplot [thick, green01270]
3842
table {%
3943
0 0
4044
0.4 nan

tests/test_patches_reference.tex

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

3-
\definecolor{color0}{rgb}{0.241237,0.296485,0.539709}
4-
\definecolor{color1}{rgb}{0.187231,0.414746,0.556547}
5-
\definecolor{color2}{rgb}{0.636902,0.856542,0.21662}
6-
\definecolor{color3}{rgb}{0.273006,0.20452,0.501721}
7-
\definecolor{color4}{rgb}{0.15627,0.489624,0.557936}
8-
\definecolor{color5}{rgb}{0.993248,0.906157,0.143936}
9-
\definecolor{color6}{rgb}{0.140536,0.530132,0.555659}
10-
\definecolor{color7}{rgb}{0.12138,0.629492,0.531973}
11-
\definecolor{color8}{rgb}{0.267004,0.004874,0.329415}
12-
\definecolor{color9}{rgb}{0.515992,0.831158,0.294279}
13-
\definecolor{color10}{rgb}{0.119699,0.61849,0.536347}
14-
\definecolor{color11}{rgb}{0.131172,0.555899,0.552459}
15-
\definecolor{color12}{rgb}{0.227802,0.326594,0.546532}
16-
\definecolor{color13}{rgb}{0.248629,0.278775,0.534556}
17-
\definecolor{color14}{rgb}{0.12156863,0.46666667,0.70588235}
3+
\definecolor{darkcyan30157136}{RGB}{30,157,136}
4+
\definecolor{darkcyan30160135}{RGB}{30,160,135}
5+
\definecolor{darkcyan33141140}{RGB}{33,141,140}
6+
\definecolor{darkcyan35135141}{RGB}{35,135,141}
7+
\definecolor{darkslateblue47105141}{RGB}{47,105,141}
8+
\definecolor{darkslateblue5883139}{RGB}{58,83,139}
9+
\definecolor{darkslateblue6175137}{RGB}{61,75,137}
10+
\definecolor{darkslateblue6371136}{RGB}{63,71,136}
11+
\definecolor{darkslateblue6952127}{RGB}{69,52,127}
12+
\definecolor{gold25323136}{RGB}{253,231,36}
13+
\definecolor{gray069}{gray}{0.6901960784313725}
14+
\definecolor{indigo68184}{RGB}{68,1,84}
15+
\definecolor{steelblue31119180}{RGB}{31,119,180}
16+
\definecolor{teal39124142}{RGB}{39,124,142}
17+
\definecolor{yellowgreen13121175}{RGB}{131,211,75}
18+
\definecolor{yellowgreen16221855}{RGB}{162,218,55}
1819

1920
\begin{axis}[
2021
colorbar,
@@ -24,14 +25,14 @@
2425
point meta min=12.062867,
2526
tick align=outside,
2627
tick pos=left,
27-
x grid style={white!69.019608!black},
28+
x grid style={gray069},
2829
xmin=0, xmax=1,
2930
xtick style={color=black},
30-
y grid style={white!69.019608!black},
31+
y grid style={gray069},
3132
ymin=0, ymax=1,
3233
ytick style={color=black}
3334
]
34-
\path [fill=color0, fill opacity=0.4]
35+
\path [fill=darkslateblue6175137, fill opacity=0.4]
3536
(axis cs:0.69646919,0.45323835)
3637
.. controls (axis cs:0.72247936,0.45323835) and (axis cs:0.74742772,0.4635723) .. (axis cs:0.76581969,0.48196427)
3738
.. controls (axis cs:0.78421166,0.50035624) and (axis cs:0.79454561,0.5253046) .. (axis cs:0.79454561,0.55131477)

tests/test_text_overlay_reference.tex

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

3-
\definecolor{gray069}{gray}{0.6901960784313725}
4-
\definecolor{gray080}{gray}{0.8}
3+
\definecolor{darkgray176}{RGB}{176,176,176}
4+
\definecolor{lightgray204}{RGB}{204,204,204}
55
\definecolor{pink255204204}{RGB}{255,204,204}
66
\definecolor{salmon255127127}{RGB}{255,127,127}
77
\definecolor{steelblue31119180}{RGB}{31,119,180}
@@ -14,14 +14,14 @@
1414
text opacity=1,
1515
at={(0.03,0.97)},
1616
anchor=north west,
17-
draw=gray080
17+
draw=lightgray204
1818
},
1919
tick align=outside,
2020
tick pos=left,
21-
x grid style={gray069},
21+
x grid style={darkgray176},
2222
xmin=-0.25, xmax=5.25,
2323
xtick style={color=black},
24-
y grid style={gray069},
24+
y grid style={darkgray176},
2525
ymin=-1.25, ymax=26.25,
2626
ytick style={color=black}
2727
]

0 commit comments

Comments
 (0)