Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 70e1dee

Browse files
committed
Add example code for current logo
1 parent 2829d51 commit 70e1dee

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed

examples/misc/logos2.py

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,148 @@
88
Thanks to Tony Yu <[email protected]> for the logo design
99
"""
1010

11+
import numpy as np
12+
import matplotlib as mpl
13+
import matplotlib.pyplot as plt
14+
import matplotlib.cm as cm
15+
from matplotlib.patches import Circle, Rectangle
16+
17+
MPL_BLUE = '#11557c'
18+
19+
20+
def create_icon_axes(fig, ax_position, lw_bars, lw_grid, lw_border, rgrid):
21+
"""
22+
Create a polar axes containing the matplotlib radar plot.
23+
24+
Parameters
25+
----------
26+
fig : matplotlib.figure.Figure
27+
The figure to draw into.
28+
ax_position : (float, float, float, float)
29+
The position of the created Axes in figure coordinates as
30+
(x, y, width, height).
31+
lw_bars : float
32+
The linewidth of the bars.
33+
lw_grid : float
34+
The linewidth of the grid.
35+
lw_border : float
36+
The linewidth of the Axes border.
37+
rgrid : array-like
38+
Positions of the radial grid.
39+
40+
Returns
41+
-------
42+
ax : matplotlib.axes.Axes
43+
The created Axes.
44+
"""
45+
with plt.rc_context({'axes.edgecolor': MPL_BLUE,
46+
'axes.linewidth': lw_border}):
47+
ax = fig.add_axes(ax_position, projection='polar')
48+
ax.set_axisbelow(True)
49+
50+
N = 7
51+
arc = 2. * np.pi
52+
theta = np.arange(0.0, arc, arc / N)
53+
radii = np.array([2, 6, 8, 7, 4, 5, 8])
54+
width = np.pi / 4 * np.array([0.4, 0.4, 0.6, 0.8, 0.2, 0.5, 0.3])
55+
bars = ax.bar(theta, radii, width=width, bottom=0.0, align='edge',
56+
edgecolor='0.1', lw=lw_bars)
57+
for r, bar in zip(radii, bars):
58+
color = *cm.jet(r / 10.)[:3], 0.6 # color from jet with alpha=0.6
59+
bar.set_facecolor(color)
60+
61+
ax.tick_params(labelbottom=False, labeltop=False,
62+
labelleft=False, labelright=False)
63+
64+
ax.grid(lw=lw_grid, ls=':', color='0.7')
65+
ax.set_rmax(9)
66+
ax.set_yticks(rgrid)
67+
68+
# the actual visible background - extends a bit beyond the axis
69+
ax.add_patch(Rectangle((0, 0), arc, 9.58,
70+
facecolor='white', zorder=0,
71+
clip_on=False, in_layout=False))
72+
return ax
73+
74+
75+
def make_logo(pixels, lw_bars, lw_grid, lw_border, rgrid, with_text=False):
76+
dpi = 100
77+
height = pixels / dpi
78+
figsize = (5 * height, height) if with_text else (height, height)
79+
fig = plt.figure(figsize=figsize, dpi=dpi)
80+
fig.patch.set_alpha(0)
81+
82+
if with_text:
83+
fig.text(0.5, 0.5, 'matplotlib', fontsize=pixels * 0.8,
84+
color=MPL_BLUE, ha='center', va='center',
85+
fontfamily='Calibri', fontweight='bold',
86+
zorder=-10)
87+
88+
ax_position = (0.535, 0.1, .17, 0.8) if with_text else (
89+
0.03, 0.03, .94, .94)
90+
ax = create_icon_axes(fig, ax_position, lw_bars, lw_grid, lw_border, rgrid)
91+
92+
return fig, ax
93+
94+
95+
params_large = {
96+
'pixels': 300,
97+
'lw_bars': 2,
98+
'lw_grid': 0.8,
99+
'lw_border': 3,
100+
'rgrid': [1, 3, 5, 7],
101+
}
102+
103+
fig, ax = make_logo(**params_large, with_text=True)
104+
plt.savefig('logo_large_text.png')
105+
106+
fig, ax = make_logo(**params_large)
107+
plt.savefig('logo_large.png')
108+
109+
##############################################################################
110+
111+
params_medium = {
112+
'pixels': 64,
113+
'lw_bars': 0.5,
114+
'lw_grid': 0.5,
115+
'lw_border': 1,
116+
'rgrid': [3, 6],
117+
}
118+
119+
make_logo(**params_medium)
120+
plt.savefig('logo_medium.png')
121+
122+
##############################################################################
123+
124+
params_small = {
125+
'pixels': 32,
126+
'lw_bars': 0.3,
127+
'lw_grid': 0.3,
128+
'lw_border': 0.3,
129+
'rgrid': [5],
130+
}
131+
132+
make_logo(**params_small)
133+
plt.savefig('logo_small.png')
134+
135+
##############################################################################
136+
137+
params_xsmall = {
138+
'pixels': 16,
139+
'lw_bars': 0.1,
140+
'lw_grid': 0.3,
141+
'lw_border': 0.3,
142+
'rgrid': [],
143+
}
144+
145+
make_logo(**params_xsmall)
146+
plt.savefig('logo_xsmall.png')
147+
148+
##############################################################################
149+
#
150+
# Old stuff
151+
# """""""""
152+
11153
import numpy as np
12154
import matplotlib as mpl
13155
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)