Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0d9af7e

Browse filesBrowse files
committed
Add example code for current logo
1 parent e285dde commit 0d9af7e
Copy full SHA for 0d9af7e

File tree

Expand file treeCollapse file tree

1 file changed

+158
-76
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+158
-76
lines changed

‎examples/misc/logos2.py

Copy file name to clipboard
+158-76Lines changed: 158 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,169 @@
11
"""
2-
================
3-
Matplotlib Logos
4-
================
2+
===============
3+
Matplotlib logo
4+
===============
55
6-
Displays some matplotlib logos.
6+
This example generates the current matplotlib logo.
77
8-
Thanks to Tony Yu <tsyu80@gmail.com> for the logo design
8+
Thanks to Tony Yu <tsyu80@gmail.com> for the original logo design.
99
"""
1010

1111
import numpy as np
1212
import matplotlib as mpl
1313
import matplotlib.pyplot as plt
1414
import matplotlib.cm as cm
15-
16-
mpl.rcParams['xtick.labelsize'] = 10
17-
mpl.rcParams['ytick.labelsize'] = 12
18-
mpl.rcParams['axes.edgecolor'] = 'gray'
19-
20-
21-
axalpha = 0.05
22-
figcolor = 'white'
23-
dpi = 80
24-
fig = plt.figure(figsize=(6, 1.1), dpi=dpi)
25-
fig.patch.set_edgecolor(figcolor)
26-
fig.patch.set_facecolor(figcolor)
27-
28-
29-
def add_math_background():
30-
ax = fig.add_axes([0., 0., 1., 1.])
31-
32-
text = []
33-
text.append(
34-
(r"$W^{3\beta}_{\delta_1 \rho_1 \sigma_2} = "
35-
r"U^{3\beta}_{\delta_1 \rho_1} + \frac{1}{8 \pi 2}"
36-
r"\int^{\alpha_2}_{\alpha_2} d \alpha^\prime_2 "
37-
r"\left[\frac{ U^{2\beta}_{\delta_1 \rho_1} - "
38-
r"\alpha^\prime_2U^{1\beta}_{\rho_1 \sigma_2} "
39-
r"}{U^{0\beta}_{\rho_1 \sigma_2}}\right]$", (0.7, 0.2), 20))
40-
text.append((r"$\frac{d\rho}{d t} + \rho \vec{v}\cdot\nabla\vec{v} "
41-
r"= -\nabla p + \mu\nabla^2 \vec{v} + \rho \vec{g}$",
42-
(0.35, 0.9), 20))
43-
text.append((r"$\int_{-\infty}^\infty e^{-x^2}dx=\sqrt{\pi}$",
44-
(0.15, 0.3), 25))
45-
text.append((r"$F_G = G\frac{m_1m_2}{r^2}$",
46-
(0.85, 0.7), 30))
47-
for eq, (x, y), size in text:
48-
ax.text(x, y, eq, ha='center', va='center', color="#11557c",
49-
alpha=0.25, transform=ax.transAxes, fontsize=size)
15+
import matplotlib.font_manager
16+
from matplotlib.patches import Circle, Rectangle, PathPatch
17+
from matplotlib.textpath import TextPath
18+
import matplotlib.transforms as mtrans
19+
20+
MPL_BLUE = '#11557c'
21+
22+
23+
def get_fontdict():
24+
# The original font is Calibri, if that is not installed, we fall back
25+
# to Carlito, which is metrically equivalent.
26+
if 'Calibri' in matplotlib.font_manager.findfont('Calibri:bold'):
27+
return {'fontfamily': 'Calibri', 'fontweight': 'bold'}
28+
if 'Carlito' in matplotlib.font_manager.findfont('Carlito:bold'):
29+
return {'fontfamily': 'Carlito', 'fontweight': 'bold'}
30+
return None
31+
32+
33+
def create_icon_axes(fig, ax_position, lw_bars, lw_grid, lw_border, rgrid):
34+
"""
35+
Create a polar axes containing the matplotlib radar plot.
36+
37+
Parameters
38+
----------
39+
fig : matplotlib.figure.Figure
40+
The figure to draw into.
41+
ax_position : (float, float, float, float)
42+
The position of the created Axes in figure coordinates as
43+
(x, y, width, height).
44+
lw_bars : float
45+
The linewidth of the bars.
46+
lw_grid : float
47+
The linewidth of the grid.
48+
lw_border : float
49+
The linewidth of the Axes border.
50+
rgrid : array-like
51+
Positions of the radial grid.
52+
53+
Returns
54+
-------
55+
ax : matplotlib.axes.Axes
56+
The created Axes.
57+
"""
58+
with plt.rc_context({'axes.edgecolor': MPL_BLUE,
59+
'axes.linewidth': lw_border}):
60+
ax = fig.add_axes(ax_position, projection='polar')
61+
ax.set_axisbelow(True)
62+
63+
N = 7
64+
arc = 2. * np.pi
65+
theta = np.arange(0.0, arc, arc / N)
66+
radii = np.array([2, 6, 8, 7, 4, 5, 8])
67+
width = np.pi / 4 * np.array([0.4, 0.4, 0.6, 0.8, 0.2, 0.5, 0.3])
68+
bars = ax.bar(theta, radii, width=width, bottom=0.0, align='edge',
69+
edgecolor='0.3', lw=lw_bars)
70+
for r, bar in zip(radii, bars):
71+
color = *cm.jet(r / 10.)[:3], 0.6 # color from jet with alpha=0.6
72+
bar.set_facecolor(color)
73+
74+
ax.tick_params(labelbottom=False, labeltop=False,
75+
labelleft=False, labelright=False)
76+
77+
ax.grid(lw=lw_grid, color='0.9')
78+
ax.set_rmax(9)
79+
ax.set_yticks(rgrid)
80+
81+
# the actual visible background - extends a bit beyond the axis
82+
ax.add_patch(Rectangle((0, 0), arc, 9.58,
83+
facecolor='white', zorder=0,
84+
clip_on=False, in_layout=False))
85+
return ax
86+
87+
88+
def create_text_axes(fig, height_px):
89+
"""Create an axes in *fig* that contains 'matplotlib' as Text."""
90+
ax = fig.add_axes((0, 0, 1, 1))
91+
ax.set_aspect("equal")
5092
ax.set_axis_off()
51-
return ax
52-
53-
54-
def add_matplotlib_text(ax):
55-
ax.text(0.95, 0.5, 'matplotlib', color='#11557c', fontsize=65,
56-
ha='right', va='center', alpha=1.0, transform=ax.transAxes)
57-
58-
59-
def add_polar_bar():
60-
ax = fig.add_axes([0.025, 0.075, 0.2, 0.85], projection='polar')
61-
62-
ax.patch.set_alpha(axalpha)
63-
ax.set_axisbelow(True)
64-
N = 7
65-
arc = 2. * np.pi
66-
theta = np.arange(0.0, arc, arc/N)
67-
radii = 10 * np.array([0.2, 0.6, 0.8, 0.7, 0.4, 0.5, 0.8])
68-
width = np.pi / 4 * np.array([0.4, 0.4, 0.6, 0.8, 0.2, 0.5, 0.3])
69-
bars = ax.bar(theta, radii, width=width, bottom=0.0)
70-
for r, bar in zip(radii, bars):
71-
bar.set_facecolor(cm.jet(r/10.))
72-
bar.set_alpha(0.6)
73-
74-
ax.tick_params(labelbottom=False, labeltop=False,
75-
labelleft=False, labelright=False)
76-
77-
ax.grid(lw=0.8, alpha=0.9, ls='-', color='0.5')
78-
79-
ax.set_yticks(np.arange(1, 9, 2))
80-
ax.set_rmax(9)
81-
8293

83-
if __name__ == '__main__':
84-
main_axes = add_math_background()
85-
add_polar_bar()
86-
add_matplotlib_text(main_axes)
87-
plt.show()
94+
fp = matplotlib.font_manager.FontProperties(family='Calibri',
95+
weight='bold')
96+
path = TextPath((0, 0), "matplotlib", size=height_px * 0.8, prop=fp)
97+
98+
angle = 4.25 # degrees
99+
trans = mtrans.Affine2D().skew_deg(angle, 0)
100+
101+
patch = PathPatch(path, transform=trans + ax.transData, color=MPL_BLUE,
102+
lw=0)
103+
ax.add_patch(patch)
104+
ax.autoscale()
105+
106+
107+
def make_logo(height_px, lw_bars, lw_grid, lw_border, rgrid, with_text=False):
108+
"""
109+
Create a full figure with the Matplotlib logo.
110+
111+
Parameters
112+
----------
113+
height_px : int
114+
Height of the figure in pixel.
115+
lw_bars : float
116+
The linewidth of the bar border.
117+
lw_grid : float
118+
The linewidth of the grid.
119+
lw_border : float
120+
The linewidth of icon border.
121+
rgrid : sequence of float
122+
The radial grid positions.
123+
with_text : bool
124+
Whether to draw only the icon or to include 'matplotlib' as text.
125+
"""
126+
dpi = 100
127+
height = height_px / dpi
128+
figsize = (5 * height, height) if with_text else (height, height)
129+
fig = plt.figure(figsize=figsize, dpi=dpi)
130+
fig.patch.set_alpha(0)
131+
132+
if with_text:
133+
create_text_axes(fig, height_px)
134+
ax_pos = (0.535, 0.12, .17, 0.75) if with_text else (0.03, 0.03, .94, .94)
135+
ax = create_icon_axes(fig, ax_pos, lw_bars, lw_grid, lw_border, rgrid)
136+
137+
return fig, ax
138+
139+
##############################################################################
140+
# A large logo:
141+
142+
params_large = {
143+
'height_px': 110,
144+
'lw_bars': 0.7,
145+
'lw_grid': 0.5,
146+
'lw_border': 1,
147+
'rgrid': [1, 3, 5, 7],
148+
}
149+
150+
make_logo(**params_large)
151+
152+
##############################################################################
153+
# A small 32px logo:
154+
155+
params_32px = {
156+
'height_px': 32,
157+
'lw_bars': 0.3,
158+
'lw_grid': 0.3,
159+
'lw_border': 0.3,
160+
'rgrid': [5],
161+
}
162+
163+
make_logo(**params_32px)
164+
165+
##############################################################################
166+
# A large logo including text, as used on the matplotlib website.
167+
168+
169+
make_logo(**params_large, with_text=True)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.