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

Skip to content

Commit 9fc11de

Browse files
authored
Merge pull request matplotlib#61 from jimustafa/master
Automatically generated logo for the cheatsheets
2 parents 12b2f78 + 9ad6dbd commit 9fc11de

13 files changed

+235
-76
lines changed

.bumpversion.cfg

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[bumpversion]
2+
current_version = 3.4.2
3+
4+
[bumpversion:glob:./handout-*.tex]
5+
search = Matplotlib {current_version}
6+
replace = Matplotlib {new_version}
7+
8+
[bumpversion:file:./requirements/requirements.in]
9+
search = matplotlib=={current_version}
10+
replace = matplotlib=={new_version}

.github/workflows/main.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/checkout@v2
1616
- uses: actions/setup-python@v2
1717
with:
18-
python-version: 3.6
18+
python-version: 3.7
1919
- name: Install dependencies
2020
run: |
2121
sudo apt update
@@ -25,7 +25,6 @@ jobs:
2525
libproj-dev \
2626
poppler-utils
2727
python -m pip install --upgrade pip
28-
pip install -r requirements/requirements-base.txt
2928
pip install -r requirements/requirements.txt
3029
- name: Install Tex Live
3130
run: |
@@ -45,7 +44,7 @@ jobs:
4544
make -C fonts/
4645
cp -r fonts/ /usr/share/fonts/
4746
fc-cache
48-
make figures cheatsheets handouts
47+
make all
4948
- name: Check layouts
5049
run: |
5150
set -x

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ SRC := $(wildcard *.tex)
44
default: all
55

66
.PHONY: all
7-
all: figures cheatsheets
7+
all: logos figures cheatsheets handouts
8+
9+
.PHONY: logos
10+
logos:
11+
cd logos && python mpl-logos2.py && pdfcrop mpl-logo2.pdf mpl-logo2.pdf
812

913
.PHONY: figures
1014
figures:
@@ -31,6 +35,7 @@ fonts:
3135

3236
.PHONY: clean
3337
clean: $(SRC)
38+
- rm ./logos/mpl-logo2.pdf
3439
git clean -f -X ./figures/
3540
git clean -f ./scripts/*.pdf
3641
latexmk -c $^

cheatsheets.tex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@
261261

262262
\begin{multicols*}{5}
263263

264-
\includegraphics[width=\columnwidth]{matplotlib.pdf}
264+
\includegraphics[width=\columnwidth]{mpl-logo2.pdf}
265265
%\textbf{\Large \RobotoCon Matplotlib 3.2 cheat sheet}\\
266266
%{\ttfamily https://matplotlib.org} \hfill CC-BY 4.0
267267
% \bigskip
@@ -1038,7 +1038,8 @@
10381038
\end{myboxed}
10391039
%
10401040
\begin{center}
1041-
\href{https://github.com/matplotlib/cheatsheets}{Matplotlib Cheatsheets} (c) 2020 Nicolas P. Rougier\\
1041+
\href{https://github.com/matplotlib/cheatsheets}{Matplotlib Cheatsheets}\\
1042+
Copyright (c) 2021 Matplotlib Development Team\\
10421043
Released under a CC-BY 4.0 International License\\
10431044
\smallskip
10441045
\includegraphics[width=\columnwidth]{numfocus.png}

handout-beginner.tex

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,12 @@ \subsection*{\rmfamily Save \mdseries (bitmap or vector format)}
296296
%
297297
\vfill
298298
%
299-
{\scriptsize Matplotlib 3.2 handout for beginners. Copyright (c)
300-
2020 Nicolas P. Rougier. Released under a CC-BY International 4.0
301-
License. Supported by NumFocus Grant \#12345.\par}
299+
{\scriptsize
300+
Matplotlib 3.4.2 handout for beginners.
301+
Copyright (c) 2021 Matplotlib Development Team.
302+
Released under a CC-BY 4.0 International License.
303+
Supported by NumFOCUS.
304+
\par}
302305

303306
\end{multicols*}
304307
\end{document}

handout-intermediate.tex

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ \subsection*{\rmfamily Colors}
182182
%\includegraphics[width=\linewidth]{colormap-magma.pdf} \medskip
183183

184184
% -----------------------------------------------------------------------------
185+
\vspace{-1em}
185186
\subsection*{\rmfamily Size \& DPI}
186187

187188
Consider a square figure to be included in a two-columns A4 paper with
@@ -196,9 +197,12 @@ \subsection*{\rmfamily Size \& DPI}
196197

197198
\vfill
198199
%
199-
{\scriptsize Matplotlib 3.2 handout for intermediate users. Copyright
200-
(c) 2020 Nicolas P. Rougier. Released under a CC-BY 4.0
201-
License. Supported by NumFocus Grant \#12345.\par}
200+
{\scriptsize
201+
Matplotlib 3.4.2 handout for intermediate users.
202+
Copyright (c) 2021 Matplotlib Development Team.
203+
Released under a CC-BY 4.0 International License.
204+
Supported by NumFOCUS.
205+
\par}
202206

203207

204208

handout-tips.tex

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,12 @@ \subsection*{\rmfamily Read the documentation}
242242

243243
\vfill
244244
%
245-
{\scriptsize Matplotlib 3.2 handout for tips \& tricks.
246-
Copyright (c) 2020 Nicolas P. Rougier.
247-
Released under a CC-BY 4.0 License.
248-
Supported by NumFocus Grant \#12345.\par}
245+
{\scriptsize
246+
Matplotlib 3.4.2 handout for tips \& tricks.
247+
Copyright (c) 2021 Matplotlib Development Team.
248+
Released under a CC-BY 4.0 International License.
249+
Supported by NumFOCUS.
250+
\par}
249251

250252

251253

logos/mpl-logos2.py

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
"""
2+
===============
3+
Matplotlib logo
4+
===============
5+
6+
This example generates the current matplotlib logo.
7+
"""
8+
9+
import numpy as np
10+
import matplotlib.pyplot as plt
11+
import matplotlib.cm as cm
12+
import matplotlib.font_manager
13+
from matplotlib.patches import Rectangle, PathPatch
14+
from matplotlib.textpath import TextPath
15+
import matplotlib.transforms as mtrans
16+
17+
MPL_BLUE = '#11557c'
18+
19+
20+
def get_font_properties():
21+
# The original font is Calibri, if that is not installed, we fall back
22+
# to Carlito, which is metrically equivalent.
23+
if 'Calibri' in matplotlib.font_manager.findfont('Calibri:bold'):
24+
return matplotlib.font_manager.FontProperties(family='Calibri',
25+
weight='bold')
26+
if 'Carlito' in matplotlib.font_manager.findfont('Carlito:bold'):
27+
print('Original font not found. Falling back to Carlito. '
28+
'The logo text will not be in the correct font.')
29+
return matplotlib.font_manager.FontProperties(family='Carlito',
30+
weight='bold')
31+
print('Original font not found. '
32+
'The logo text will not be in the correct font.')
33+
return None
34+
35+
36+
def create_icon_axes(fig, ax_position, lw_bars, lw_grid, lw_border, rgrid):
37+
"""
38+
Create a polar axes containing the matplotlib radar plot.
39+
40+
Parameters
41+
----------
42+
fig : matplotlib.figure.Figure
43+
The figure to draw into.
44+
ax_position : (float, float, float, float)
45+
The position of the created Axes in figure coordinates as
46+
(x, y, width, height).
47+
lw_bars : float
48+
The linewidth of the bars.
49+
lw_grid : float
50+
The linewidth of the grid.
51+
lw_border : float
52+
The linewidth of the Axes border.
53+
rgrid : array-like
54+
Positions of the radial grid.
55+
56+
Returns
57+
-------
58+
ax : matplotlib.axes.Axes
59+
The created Axes.
60+
"""
61+
with plt.rc_context({'axes.edgecolor': MPL_BLUE,
62+
'axes.linewidth': lw_border}):
63+
ax = fig.add_axes(ax_position, projection='polar')
64+
ax.set_axisbelow(True)
65+
66+
N = 7
67+
arc = 2. * np.pi
68+
theta = np.arange(0.0, arc, arc / N)
69+
radii = np.array([2, 6, 8, 7, 4, 5, 8])
70+
width = np.pi / 4 * np.array([0.4, 0.4, 0.6, 0.8, 0.2, 0.5, 0.3])
71+
bars = ax.bar(theta, radii, width=width, bottom=0.0, align='edge',
72+
edgecolor='0.3', lw=lw_bars)
73+
for r, bar in zip(radii, bars):
74+
color = *cm.jet(r / 10.)[:3], 0.6 # color from jet with alpha=0.6
75+
bar.set_facecolor(color)
76+
77+
ax.tick_params(labelbottom=False, labeltop=False,
78+
labelleft=False, labelright=False)
79+
80+
ax.grid(lw=lw_grid, color='0.9')
81+
ax.set_rmax(9)
82+
ax.set_yticks(rgrid)
83+
84+
# the actual visible background - extends a bit beyond the axis
85+
ax.add_patch(Rectangle((0, 0), arc, 9.58,
86+
facecolor='white', zorder=0,
87+
clip_on=False, in_layout=False))
88+
return ax
89+
90+
91+
def create_text_axes(fig, height_px):
92+
"""Create an axes in *fig* that contains 'matplotlib' as Text."""
93+
ax = fig.add_axes((0, 0, 1, 1))
94+
ax.set_aspect("equal")
95+
ax.set_axis_off()
96+
97+
path = TextPath((0, 0), "matplotlib", size=height_px * 0.8,
98+
prop=get_font_properties())
99+
100+
fp = get_font_properties()
101+
fp.set_weight('light')
102+
path1 = TextPath((80, -13), 'Cheat sheet', size=height_px * 0.12,
103+
prop=fp)
104+
path2 = TextPath((310, -13), f'Version {matplotlib. __version__}',
105+
size=height_px * 0.12,
106+
prop=fp)
107+
108+
angle = 4.25 # degrees
109+
trans = mtrans.Affine2D().skew_deg(angle, 0)
110+
111+
patch = PathPatch(path, transform=trans + ax.transData, color=MPL_BLUE,
112+
lw=0)
113+
patch1 = PathPatch(path1, transform=trans + ax.transData, color=MPL_BLUE,
114+
lw=0)
115+
patch2 = PathPatch(path2, color=MPL_BLUE,
116+
lw=0)
117+
118+
ax.add_patch(patch)
119+
ax.add_patch(patch1)
120+
ax.add_patch(patch2)
121+
ax.autoscale()
122+
123+
124+
def make_logo(height_px, lw_bars, lw_grid, lw_border, rgrid, with_text=False):
125+
"""
126+
Create a full figure with the Matplotlib logo.
127+
128+
Parameters
129+
----------
130+
height_px : int
131+
Height of the figure in pixel.
132+
lw_bars : float
133+
The linewidth of the bar border.
134+
lw_grid : float
135+
The linewidth of the grid.
136+
lw_border : float
137+
The linewidth of icon border.
138+
rgrid : sequence of float
139+
The radial grid positions.
140+
with_text : bool
141+
Whether to draw only the icon or to include 'matplotlib' as text.
142+
"""
143+
dpi = 100
144+
height = height_px / dpi
145+
figsize = (5 * height, height) if with_text else (height, height)
146+
fig = plt.figure(figsize=figsize, dpi=dpi)
147+
fig.patch.set_alpha(0)
148+
149+
if with_text:
150+
create_text_axes(fig, height_px)
151+
ax_pos = (0.535, 0.12, .17, 0.75) if with_text else (0.03, 0.03, .94, .94)
152+
ax = create_icon_axes(fig, ax_pos, lw_bars, lw_grid, lw_border, rgrid)
153+
154+
fig.savefig('mpl-logo2.pdf')
155+
156+
return fig, ax
157+
158+
##############################################################################
159+
# A large logo:
160+
161+
make_logo(height_px=110, lw_bars=0.7, lw_grid=0.5, lw_border=1,
162+
rgrid=[1, 3, 5, 7])
163+
164+
##############################################################################
165+
# A small 32px logo:
166+
167+
make_logo(height_px=32, lw_bars=0.3, lw_grid=0.3, lw_border=0.3, rgrid=[5])
168+
169+
##############################################################################
170+
# A large logo including text, as used on the matplotlib website.
171+
172+
make_logo(height_px=110, lw_bars=0.7, lw_grid=0.5, lw_border=1,
173+
rgrid=[1, 3, 5, 7], with_text=True)
174+
# plt.show()

requirements/Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
default: all
33

44
.PHONY: all
5-
all: requirements-base.txt requirements.txt
5+
all: requirements.txt
66

77
.PHONY: install
8-
install: requirements-base.txt requirements.txt
8+
install: requirements.txt
99
pip-sync $^
1010

11-
requirements.txt: requirements-base.txt
12-
1311
%.txt: %.in
1412
pip-compile $<

requirements/requirements-base.in

Lines changed: 0 additions & 2 deletions
This file was deleted.

requirements/requirements-base.txt

Lines changed: 0 additions & 27 deletions
This file was deleted.

requirements/requirements.in

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
-c ./requirements-base.txt
2-
3-
cartopy
4-
fonttools[woff]
5-
matplotlib
1+
bump2version
2+
cartopy==0.19.0.post1
3+
matplotlib==3.4.2
4+
pip-tools
65
pre-commit
76
scipy
87

0 commit comments

Comments
 (0)