-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
the font set {"font.sans-serif":"SimHei"} is ignored by plt.rc_context in jupyter #20738
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
Comments
@CatNofishing Can you determine if the issue is the rcparam is being not being set, that the rcparam is being set, but the font is not found, or if it is being set and ignored for some other reason? How did you generate the corect output? |
@tacaswell the font set {"font.sans-serif":"SimHei"} is ignored by plt.rc_context in jupyter notebook. the incorect output code:import matplotlib.pyplot as plt
rc={
"font.sans-serif":"SimHei"
}
with plt.rc_context(rc):
plt.xlabel("上海市") the correct output code:import matplotlib.pyplot as plt
rc={
"font.sans-serif":"SimHei"
}
plt.rcParams.update(rc)
plt.xlabel("上海室") another intersting thing is that if you add plt.show() in rc_context() end ,it works well in jupyter.import matplotlib.pyplot as plt
rc={
"font.sans-serif":"SimHei"
}
with plt.rc_context(rc):
plt.xlabel("上海市")
plt.show() It seems that xlabel is not rendered correctly in jupyter when you use plt.rc_context |
I think this is working as expected. If you don't render the label until after the rccontext then it renders in the global context. This is simply a case of it being confusing about what Matplotlib applies at instantiation of the label versus when it is rendered. |
@jklymak Thanks your reply, I still can't understand what you mean,so it is not a bug?😂 |
The font can either be applied to the string when you call xlabel, or it can be applied to the string when the figure is rendered (shown or printed). You expect the first, but unfortunately Matplotlib does the second. |
Bug report
plt.rc_context {"font.sans-serif":"SimHei"} does not work , but it work well in plt.rcParams.update(rc).
Code for reproduction
Expected outcome
The text was updated successfully, but these errors were encountered: