Skip to content

Commit fe1c4f3

Browse files
committed
small improvement for colors
1 parent 5791ebc commit fe1c4f3

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

matplotlib2tikz/color.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# -*- coding: utf-8 -*-
22
#
3+
from __future__ import division
4+
35
import matplotlib as mpl
46
import numpy
57

@@ -18,6 +20,15 @@ def mpl_color2xcolor(data, matplotlib_color):
1820
xcol = None
1921
# RGB values (as taken from xcolor.dtx):
2022
available_colors = {
23+
# List white first such that for gray values, the combination
24+
# white!<x>!black is preferred over, e.g., gray!<y>!black. Note that
25+
# the order of the dictionary is respected from Python 3.6 on.
26+
'white': numpy.array([1, 1, 1]),
27+
'lightgray': numpy.array([0.75, 0.75, 0.75]),
28+
'gray': numpy.array([0.5, 0.5, 0.5]),
29+
'darkgray': numpy.array([0.25, 0.25, 0.25]),
30+
'black': numpy.array([0, 0, 0]),
31+
#
2132
'red': numpy.array([1, 0, 0]),
2233
'green': numpy.array([0, 1, 0]),
2334
'blue': numpy.array([0, 0, 1]),
@@ -28,11 +39,6 @@ def mpl_color2xcolor(data, matplotlib_color):
2839
'purple': numpy.array([0.75, 0, 0.25]),
2940
'teal': numpy.array([0, 0.5, 0.5]),
3041
'violet': numpy.array([0.5, 0, 0.5]),
31-
'black': numpy.array([0, 0, 0]),
32-
'darkgray': numpy.array([0.25, 0.25, 0.25]),
33-
'gray': numpy.array([0.5, 0.5, 0.5]),
34-
'lightgray': numpy.array([0.75, 0.75, 0.75]),
35-
'white': numpy.array([1, 1, 1])
3642
# The colors cyan, magenta, yellow, and olive are also
3743
# predefined by xcolor, but their RGB approximation of the
3844
# native CMYK values is not very good. Don't use them here.
@@ -71,4 +77,5 @@ def mpl_color2xcolor(data, matplotlib_color):
7177
# Lookup failed, add it to the custom list.
7278
xcol = 'color' + str(len(data['custom colors']))
7379
data['custom colors'][xcol] = my_col[:3]
80+
7481
return data, xcol, my_col

test/test_legend_best_location.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ def plot():
6262

6363
def test():
6464
phash = helpers.Phash(plot())
65-
assert phash.phash == '879d990d0e8f7c1c', phash.get_details()
65+
assert phash.phash == '971d991d1c877c1c', phash.get_details()
6666
return

test/test_legends2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ def plot():
3232

3333
def test():
3434
phash = helpers.Phash(plot())
35-
assert phash.phash == '7b447a5262d4952f', phash.get_details()
35+
assert phash.phash == '7f447a5266d4812f', phash.get_details()
3636
return

test/test_sharex_and_y.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ def test():
2222
phash = helpers.Phash(plot())
2323
assert phash.phash == 'bbcdbc12ef119812', phash.get_details()
2424
return
25+
26+
27+
if __name__ == '__main__':
28+
plot()
29+
plt.show()

0 commit comments

Comments
 (0)