Skip to content

Do not remove serif font family in pgf example to avoid Warning #20945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

FranzForstmayr
Copy link

Currently the pgf_plots example throws a warning that the pgf font serif is not found.
This PR fixes this behaviour.

Fixes #20850

PR Summary

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • [N/A] New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

Copy link
Contributor

@aitikgupta aitikgupta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why there's no "Check the rendered docs here!" GitHub Action check for this PR.. but this looks good, thanks!

@QuLogic
Copy link
Member

QuLogic commented Aug 30, 2021

Because Circle hasn't run a doc CI build at all.

@QuLogic QuLogic closed this Aug 30, 2021
@QuLogic QuLogic reopened this Aug 30, 2021
@QuLogic QuLogic added this to the v3.5.0 milestone Aug 30, 2021
@aitikgupta
Copy link
Contributor

aitikgupta commented Aug 31, 2021

There seems to be a separate bug; that the Cursive font-family isn't found by CI:
https://63196-1385122-gh.circle-artifacts.com/0/doc/build/html/gallery/userdemo/pgf_fonts.html

This is true for other PRs too (for example, the most recent #20949):
https://63199-1385122-gh.circle-artifacts.com/0/doc/build/html/gallery/userdemo/pgf_fonts.html

Though It did use to find the cursive font-family for the previous builds (on stable): https://matplotlib.org/stable/gallery/userdemo/pgf_fonts.html

@QuLogic
Copy link
Member

QuLogic commented Aug 31, 2021

/stable/ is built on my machine, not CI. You can't compare it to /devdocs/ or PR builds.

@QuLogic
Copy link
Member

QuLogic commented Aug 31, 2021

It appears that we use Comic (Neue, Sans MS) because it's already listed in font.cursive, but it's not available on CI. Felipa is also listed in that font list, and is explicitly installed on CI, so maybe we should switch to that instead?

@anntzer
Copy link
Contributor

anntzer commented Sep 9, 2021

As discussed during the dev call this is actually hiding a bug that I bisected back to #10339; the fix is clear looking at that PR, and should be something like

diff --git i/lib/matplotlib/backends/backend_pgf.py w/lib/matplotlib/backends/backend_pgf.py
index 749da55966..8706fed514 100644
--- i/lib/matplotlib/backends/backend_pgf.py
+++ w/lib/matplotlib/backends/backend_pgf.py
@@ -50,9 +50,14 @@ def get_fontspec():
         for family, command in zip(families, commands):
             # 1) Forward slashes also work on Windows, so don't mess with
             # backslashes.  2) The dirname needs to include a separator.
-            path = pathlib.Path(fm.findfont(family))
-            latex_fontspec.append(r"\%s{%s}[Path=\detokenize{%s}]" % (
-                command, path.name, path.parent.as_posix() + "/"))
+            try:
+                path = pathlib.Path(
+                    fm.findfont(family, fallback_to_default=False))
+            except ValueError:
+                pass
+            else:
+                latex_fontspec.append(r"\%s{%s}[Path=\detokenize{%s}]" % (
+                    command, path.name, path.parent.as_posix() + "/"))
 
     return "\n".join(latex_fontspec)

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the above.

@jklymak
Copy link
Member

jklymak commented Sep 21, 2021

I'm moving to draft until the above is addressed. Thanks!

@jklymak jklymak marked this pull request as draft September 21, 2021 12:43
@FranzForstmayr FranzForstmayr marked this pull request as ready for review September 22, 2021 08:18
@jklymak jklymak requested a review from anntzer September 23, 2021 08:04
@anntzer
Copy link
Contributor

anntzer commented Sep 23, 2021

I think this just needs the change to the example to be reverted, but otherwise looks good.

@anntzer anntzer removed their request for review September 23, 2021 08:17
@FranzForstmayr
Copy link
Author

Reverting the change does not seem to work.
https://63832-1385122-gh.circle-artifacts.com/0/doc/build/html/gallery/userdemo/pgf_fonts.html

I can remove the empty list from the font specification again, otherwise I'm not sure how to fix this error.

@anntzer
Copy link
Contributor

anntzer commented Sep 27, 2021

Actually there's another problem with the example, which is that it doesn't actulaly use the pgf backend (which is a pity...)
One needs to add e.g. backend="pgf" to each of the savefig calls.
That then shows another problem with the example, which is that family="cursive" doesn't work, which I guess could just be documented as a limitation of backend_pgf (because TeX has \rmfamily \sffamily \ttfamily but no \cursivefamily (or \calfamily, I guess).

@jklymak jklymak marked this pull request as draft October 5, 2021 07:44
@jklymak
Copy link
Member

jklymak commented Oct 5, 2021

I popped this back to draft, but feel free to put back on the queue

@tacaswell tacaswell modified the milestones: v3.5.0, v3.6.0 Oct 13, 2021
@tacaswell
Copy link
Member

tacaswell commented Oct 20, 2021

@FranzForstmayr Can you squash this into one commit so we do not have the commit and it's reversion in the history? You can do this with git rebase -i. Please ask if you need help!

Do not remove serif font family in pgf example to avoid Warning

Add requested changes

Revert "Fix matplotlib#20850"

This reverts commit 0bff071.
@QuLogic
Copy link
Member

QuLogic commented Apr 28, 2022

Hmm, @FranzForstmayr did you intend to close this?

@FranzForstmayr
Copy link
Author

Yes, as there is a more recent PR (#22111) about this topic.

@QuLogic QuLogic removed this from the v3.6.0 milestone Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Warning: Font Family not found
6 participants