8000 added some htdocs files · matplotlib/matplotlib@5535fe2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5535fe2

Browse files
committed
added some htdocs files
svn path=/trunk/matplotlib/; revision=142
1 parent 29dfcd2 commit 5535fe2

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

examples/colours.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
Some simple functions to generate colours.
3+
"""
4+
from Numeric import asarray
5+
from matplotlib.mlab import linspace
6+
from matplotlib.backend_bases import arg_to_rgb
7+
8+
def pastel(colour, weight=2.4):
9+
""" Convert colour into a nice pastel shade"""
10+
rgb = asarray(arg_to_rgb(colour))
11+
# scale colour
12+
maxc = max(rgb)
13+
if maxc < 1.0 and maxc > 0:
14+
# scale colour
15+
scale = 1.0 / maxc
16+
rgb = rgb * scale
17+
# now decrease saturation
18+
total = sum(rgb)
19+
slack = 0
20+
for x in rgb:
21+
slack += 1.0 - x
22+
23+
# want to increase weight from total to weight
24+
# pick x s.t. slack * x == weight - total
25+
# x = (weight - total) / slack
26+
x = (weight - total) / slack
27+
28+
rgb = [c + (x * (1.0-c)) for c in rgb]
29+
30+
return rgb
31+
32+
def get_colours(n):
33+
""" Return n pastel colours. """
34+
base = asarray([[1,0,0], [0,1,0], [0,0,1]])
35+
36+
if n <= 3:
37+
return base[0:n]
38+
39+
# how many new colours to we need to insert between
40+
# red and green and between green and blue?
41+
needed = (((n - 3) + 1) / 2, (n - 3) / 2)
42+
43+
colours = []
44+
for start in (0, 1):
45+
for x in linspace(0, 1, needed[start]+2):
46+
colours.append((base[start] * (1.0 - x)) +
47+
(base[start+1] * x))
48+
49+
return [pastel(c) for c in colours[0:n]]
50+

examples/vertical_ticklabels.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from matplotlib.matlab import *
2+
3+
plot([1,2,3,4], [1,4,9,16])
4+
set(gca(), 'xticks', [1,2,3,4])
5+
t = set(gca(), 'xticklabels', ['Frogs', 'Hogs', 'Bogs', 'Slogs'])
6+
set(t, 'rotation', 'vertical')
7+
show()

0 commit comments

Comments
 (0)
0