Skip to content

Commit f4f1fbf

Browse files
committed
Merge branch 'main' into output-base-name
2 parents c8eba90 + f6b77d2 commit f4f1fbf

File tree

11 files changed

+215
-115
lines changed

11 files changed

+215
-115
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
persist-credentials: false
3333

3434
- name: Initialize CodeQL
35-
uses: github/codeql-action/init@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
35+
uses: github/codeql-action/init@fca7ace96b7d713c7035871441bd52efbe39e27e # v3.28.19
3636
with:
3737
languages: ${{ matrix.language }}
3838

@@ -43,4 +43,4 @@ jobs:
4343
pip install --user -v .
4444
4545
- name: Perform CodeQL Analysis
46-
uses: github/codeql-action/analyze@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
46+
uses: github/codeql-action/analyze@fca7ace96b7d713c7035871441bd52efbe39e27e # v3.28.19
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
=====================
3+
Histogram as colorbar
4+
=====================
5+
6+
This example demonstrates how to use a colored histogram instead of a colorbar
7+
to not only show the color-to-value mapping, but also visualize the
8+
distribution of values.
9+
"""
10+
11+
import matplotlib.pyplot as plt
12+
import numpy as np
13+
14+
import matplotlib.colors as mcolors
15+
16+
# surface data
17+
delta = 0.025
18+
x = y = np.arange(-2.0, 2.0, delta)
19+
X, Y = np.meshgrid(x, y)
20+
Z1 = np.exp(-(((X + 1) * 1.3) ** 2) - ((Y + 1) * 1.3) ** 2)
21+
Z2 = 2.5 * np.exp(-((X - 1) ** 2) - (Y - 1) ** 2)
22+
Z = Z1**0.25 - Z2**0.5
23+
24+
# colormap & normalization
25+
bins = 30
26+
cmap = plt.get_cmap("RdYlBu_r")
27+
bin_edges = np.linspace(Z.min(), Z.max(), bins + 1)
28+
norm = mcolors.BoundaryNorm(bin_edges, cmap.N)
29+
30+
# main plot
31+
fig, ax = plt.subplots(layout="constrained")
32+
im = ax.imshow(Z, cmap=cmap, origin="lower", extent=[-3, 3, -3, 3], norm=norm)
33+
34+
# inset histogram
35+
cax = ax.inset_axes([1.18, 0.02, 0.25, 0.95]) # left, bottom, width, height
36+
37+
# plot histogram
38+
counts, _ = np.histogram(Z, bins=bin_edges)
39+
midpoints = (bin_edges[:-1] + bin_edges[1:]) / 2
40+
distance = midpoints[1] - midpoints[0]
41+
cax.barh(midpoints, counts, height=0.8 * distance, color=cmap(norm(midpoints)))
42+
43+
# styling
44+
cax.spines[:].set_visible(False)
45+
cax.set_yticks(bin_edges)
46+
cax.tick_params(axis="both", which="both", length=0)
47+
48+
plt.show()

galleries/users_explain/text/fonts.py

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,35 @@
2727
Matplotlib supports three font specifications (in addition to pdf 'core fonts',
2828
which are explained later in the guide):
2929
30-
.. list-table:: Type of Fonts
31-
:header-rows: 1
32-
33-
* - Type 1 (PDF)
34-
- Type 3 (PDF/PS)
35-
- TrueType (PDF)
36-
* - One of the oldest types, introduced by Adobe
37-
- Similar to Type 1 in terms of introduction
38-
- Newer than previous types, used commonly today, introduced by Apple
39-
* - Restricted subset of PostScript, charstrings are in bytecode
40-
- Full PostScript language, allows embedding arbitrary code
41-
(in theory, even render fractals when rasterizing!)
42-
- Include a virtual machine that can execute code!
43-
* - These fonts support font hinting
44-
- Do not support font hinting
45-
- Hinting supported (virtual machine processes the "hints")
46-
* - Non-subsetted through Matplotlib
47-
- Subsetted via external module ttconv
48-
- Subsetted via external module
49-
`fontTools <https://github.com/fonttools/fonttools>`__
30+
.. table:: Type of Fonts
31+
32+
+--------------------------+----------------------------+----------------------------+
33+
| Type 1 (PDF with usetex) | Type 3 (PDF/PS) | TrueType (PDF) |
34+
+==========================+============================+============================+
35+
| One of the oldest types, | Similar to Type 1 in | Newer than previous types, |
36+
| introduced by Adobe | terms of introduction | used commonly today, |
37+
| | | introduced by Apple |
38+
+--------------------------+----------------------------+----------------------------+
39+
| Restricted subset of | Full PostScript language, | Includes a virtual machine |
40+
| PostScript, charstrings | allows embedding arbitrary | that can execute code! |
41+
| are in bytecode | code (in theory, even | |
42+
| | render fractals when | |
43+
| | rasterizing!) | |
44+
+--------------------------+----------------------------+----------------------------+
45+
| Supports font | Does not support font | Supports font hinting |
46+
| hinting | hinting | (virtual machine processes |
47+
| | | the "hints") |
48+
+--------------------------+----------------------------+----------------------------+
49+
| Subsetted by code in | Subsetted via external module |
50+
| `matplotlib._type1font` | `fontTools <https://github.com/fonttools/fonttools>`__ |
51+
+--------------------------+----------------------------+----------------------------+
5052
5153
.. note::
5254
5355
Adobe disabled__ support for authoring with Type 1 fonts in January 2023.
56+
Matplotlib uses Type 1 fonts for compatibility with TeX; when the usetex
57+
feature is used with the PDF backend, Matplotlib reads the fonts used by
58+
the TeX engine, which are usually Type 1.
5459
5560
__ https://helpx.adobe.com/fonts/kb/postscript-type-1-fonts-end-of-support.html
5661
@@ -83,14 +88,12 @@
8388
files, particularly with fonts with many glyphs such as those that support CJK
8489
(Chinese/Japanese/Korean).
8590
86-
The solution to this problem is to subset the fonts used in the document and
87-
only embed the glyphs actually used. This gets both vector text and small
88-
files sizes. Computing the subset of the font required and writing the new
89-
(reduced) font are both complex problem and thus Matplotlib relies on
90-
`fontTools <https://fonttools.readthedocs.io/en/latest/>`__ and a vendored fork
91-
of ttconv.
92-
93-
Currently Type 3, Type 42, and TrueType fonts are subsetted. Type 1 fonts are not.
91+
To keep the output size reasonable while using vector fonts,
92+
Matplotlib embeds only the glyphs that are actually used in the document.
93+
This is known as font subsetting.
94+
Computing the font subset and writing the reduced font are both complex problems,
95+
which Matplotlib solves in most cases by using the
96+
`fontTools <https://fonttools.readthedocs.io/en/latest/>`__ library.
9497
9598
Core Fonts
9699
^^^^^^^^^^

lib/matplotlib/backends/backend_ps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ class RendererPS(_backend_pdf_ps.RendererPDFPSBase):
406406
def __init__(self, width, height, pswriter, imagedpi=72):
407407
# Although postscript itself is dpi independent, we need to inform the
408408
# image code about a requested dpi to generate high resolution images
409-
# and them scale them before embedding them.
409+
# and then scale them before embedding them.
410410
super().__init__(width, height)
411411
self._pswriter = pswriter
412412
if mpl.rcParams['text.usetex']:

lib/matplotlib/cbook.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,6 +2228,9 @@ def _g_sig_digits(value, delta):
22282228
Return the number of significant digits to %g-format *value*, assuming that
22292229
it is known with an error of *delta*.
22302230
"""
2231+
# For inf or nan, the precision doesn't matter.
2232+
if not math.isfinite(value):
2233+
return 0
22312234
if delta == 0:
22322235
if value == 0:
22332236
# if both value and delta are 0, np.spacing below returns 5e-324
@@ -2241,11 +2244,10 @@ def _g_sig_digits(value, delta):
22412244
# digits before the decimal point (floor(log10(45.67)) + 1 = 2): the total
22422245
# is 4 significant digits. A value of 0 contributes 1 "digit" before the
22432246
# decimal point.
2244-
# For inf or nan, the precision doesn't matter.
22452247
return max(
22462248
0,
22472249
(math.floor(math.log10(abs(value))) + 1 if value else 1)
2248-
- math.floor(math.log10(delta))) if math.isfinite(value) else 0
2250+
- math.floor(math.log10(delta)))
22492251

22502252

22512253
def _unikey_or_keysym_to_mplkey(unikey, keysym):

lib/matplotlib/colors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ def with_alpha(self, alpha):
949949
if not isinstance(alpha, Real):
950950
raise TypeError(f"'alpha' must be numeric or None, not {type(alpha)}")
951951
if not 0 <= alpha <= 1:
952-
ValueError("'alpha' must be between 0 and 1, inclusive")
952+
raise ValueError("'alpha' must be between 0 and 1, inclusive")
953953
new_cm = self.copy()
954954
if not new_cm._isinit:
955955
new_cm._init()
Binary file not shown.
Loading

0 commit comments

Comments
 (0)