21
21
import matplotlib .pyplot as plt
22
22
from matplotlib import transforms
23
23
24
- def rainbow_text (x ,y , ls , lc , ** kw ):
24
+ def rainbow_text (x , y , strings , colors , ** kw ):
25
25
"""
26
- Take a list of strings ``ls `` and colors ``lc `` and place them next to each
27
- other, with text ls [i] being shown in color lc [i].
26
+ Take a list of ``strings `` and colors ``colors `` and place them next to each
27
+ other, with text strings [i] being shown in colors [i].
28
28
29
29
This example shows how to do both vertical and horizontal text, and will
30
30
pass all keyword arguments to plt.text, so you can set the font size,
@@ -34,14 +34,14 @@ def rainbow_text(x,y,ls,lc,**kw):
34
34
fig = plt .gcf ()
35
35
36
36
#horizontal version
37
- for s ,c in zip (ls , lc ):
37
+ for s ,c in zip (strings , colors ):
38
38
text = plt .text (x , y , " " + s + " " , color = c , transform = t , ** kw )
39
39
text .draw (fig .canvas .get_renderer ())
40
40
ex = text .get_window_extent ()
41
41
t = transforms .offset_copy (text ._transform , x = ex .width , units = 'dots' )
42
42
43
43
#vertical version
44
- for s ,c in zip (ls , lc ):
44
+ for s ,c in zip (strings , colors ):
45
45
text = plt .text (x , y , " " + s + " " , color = c , transform = t ,
46
46
rotation = 90 , va = 'bottom' , ha = 'center' , ** kw )
47
47
text .draw (fig .canvas .get_renderer ())
0 commit comments