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

Skip to content

Update font in matplotlib #12

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

Merged
merged 2 commits into from
Mar 19, 2025
Merged

Update font in matplotlib #12

merged 2 commits into from
Mar 19, 2025

Conversation

HumphreyYang
Copy link
Collaborator

Hi @mmcky,

On a second thought, I think we should add them to every lecture with matplotlib, and then ask RAs to review if they are needed.

This way we can avoid build errors first.

This PR should fix #7.

Best,
Humphrey

@mmcky
Copy link
Contributor

mmcky commented Mar 18, 2025

thanks @HumphreyYang. It appears this isn't the driving issue though

latex was not able to process the following string:
b'$E[y_t]$ \\u968f\\u65f6\\u95f4\\u53d8\\u5316'

still getting this lecture failure. I will have to take a closer look.

@HumphreyYang
Copy link
Collaborator Author

Many thanks @mmcky,

This is wierd, but I think it might still be beneficial to have these added to the matplotlib paramters : )

@mmcky
Copy link
Contributor

mmcky commented Mar 18, 2025

thanks @HumphreyYang that cell is not working if there are ANY chinese characters used. All lines need to be removed for the latex to work. Is there an unusual character in each line? Do we need to enable an extended chinese character set?

Screenshot 2025-03-19 at 9 47 15 am

One solution is to declare any missing unicode in a preamble.

matplotlib/matplotlib#20262

but I think that is probably not a great solution in this case.

@HumphreyYang
Copy link
Collaborator Author

Many thanks @mmcky,

This is strange. I thought it is related to matplotlib titles. Is xlabel working?

@mmcky
Copy link
Contributor

mmcky commented Mar 18, 2025

Many thanks @mmcky,

This is strange. I thought it is related to matplotlib titles. Is xlabel working?

No if any combination is enabled the latex conversion fails. matplotlib uses latex rather than xelatex under the hood to render the latex math and it is struggling with the chinese characters.

@HumphreyYang
Copy link
Collaborator Author

Thanks @mmcky,

That's sad : ( I wonder why we did not hit this issue in the intro series.

@mmcky
Copy link
Contributor

mmcky commented Mar 18, 2025

Thanks @mmcky,

That's sad : ( I wonder why we did not hit this issue in the intro series.

It's only an issue with this one code-cell as far as I can tell. The other lectures are running fine, that is why I was wondering if there was an unusual chinese character not defined in the standard utf8?

@HumphreyYang
Copy link
Collaborator Author

Hi Matt,

Let me try to rewrite this sentence and see if we get the same errror!

@mmcky
Copy link
Contributor

mmcky commented Mar 18, 2025

Hi Matt,

Let me try to rewrite this sentence and see if we get the same errror!

It's actually an issue for that lecture more broadly. I was looking at disabling the Chinese characters in matplotlib figure generation and for some reason that lecture is having issues.

@HumphreyYang
Copy link
Collaborator Author

HumphreyYang commented Mar 18, 2025

Hi @mmcky, I think I know what happened!

I wrote this lecture with Tom and at that time I wanted to add matrices to the matplotlib plots. So I have those lines at the beginning:

mpl.rcParams['text.usetex'] = True
mpl.rcParams['text.latex.preamble'] = r'\usepackage{{amsmath}}'

Appearently this has forced matplotlib to use internel latex engine.

I guess all I need to do is to add the usage the package that support chinese characters here.

@HumphreyYang
Copy link
Collaborator Author

HumphreyYang commented Mar 18, 2025

Hi @mmcky,

I fixed Kalman_2 in the latest push! Everything now runs perfectly on my end!

@mmcky
Copy link
Contributor

mmcky commented Mar 19, 2025

Nice work @HumphreyYang. Thanks. There is starting to be a lot of setup to include the characters in latex + matplotlib

@mmcky
Copy link
Contributor

mmcky commented Mar 19, 2025

thanks @HumphreyYang -- merging this to get the cache building. I have verified local execution as well.

@mmcky mmcky merged commit f626b34 into main Mar 19, 2025
0 of 4 checks passed
@mmcky mmcky deleted the update-matplotlib branch March 19, 2025 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[kalman_2] Error in LaTeX conversion
2 participants