Hello, Attached is a small patch to add a simple color mix operation support. For example, "red!30!white" mixes 30% of red with 70% of white. The syntax is borrowed from latex xcolor package (http://www.ukern.de/tex/xcolor.html). I found it quite handy with the fancy box thing.
plt.text(0.6, 0.5, "test", size=50, rotation=30.,
bbox = dict(boxstyle="round",
fc="orange!20!white", # 20% orange + 80% white
ec="orange!50!white", # 50 % orange + 50% white
)
)
plt.text(0.5, 0.4, "test", size=50, rotation=-30.,
bbox = dict(boxstyle="square",
fc="aqua!50!green!20!white",
ec="green!40!white",
)
)
Any chance this could be included in matplotlib?
Regards,
-JJ
<<attachment: color_mix.png>>
Index: lib/matplotlib/colors.py
===================================================================
--- lib/matplotlib/colors.py (revision 6100)
+++ lib/matplotlib/colors.py (working copy)
@@ -252,7 +252,23 @@
try:
if cbook.is_string_like(arg):
- color = self.colors.get(arg, None)
+ # if arg contains "!", try color mix.
+ # e.g., "red!30!white" mixes 30% of red with 70% of white.
+ # red!40!blue!30!white means (red!40!blue)!30!white
+ # "!" is searched from the end of the string and
+ # to_rgb method is recursively called
+ ind_last = arg.rfind("!")
+ if ind_last != -1:
+ ind1 = arg.rfind("!", 0, ind_last)
+ if ind1 == -1: raise ValueError("incorrect color mix expression : %s"%(arg))
+ color1 = self.to_rgb(arg[:ind1])
+ mix = 0.01 * float(arg[ind1+1:ind_last])
+ color2 = self.to_rgb(arg[ind_last+1:])
+ color = tuple([c1*mix + c2*(1.-mix) \
+ for c1, c2 in zip(color1, color2)])
+ else:
+ color = self.colors.get(arg, None)
+
if color is None:
str1 = cnames.get(arg, arg)
if str1.startswith('#'):
------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________ Matplotlib-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
