I've found the culprit for this behavior, after struggling with the problem myself for quite some time. In the file ticker.py and the class ScalarFormatter, there is a method _set_format(). This method checks if tex is used and formats accordingly:
if self._usetex:
self.format = '$%s$' % self.format
The dollar signs cause the behavior because they mark the tick label numbers as a LaTeX math string. I deleted them and now it works as expected. Or you can delete the whole if clause as it does nothing else.
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Activity
jkrumbiegel commented on May 24, 2017
I've found the culprit for this behavior, after struggling with the problem myself for quite some time. In the file ticker.py and the class ScalarFormatter, there is a method _set_format(). This method checks if tex is used and formats accordingly:
if self._usetex:
self.format = '$%s$' % self.format
The dollar signs cause the behavior because they mark the tick label numbers as a LaTeX math string. I deleted them and now it works as expected. Or you can delete the whole if clause as it does nothing else.
ImportanceOfBeingErnest commented on Jul 21, 2018
This means that another possible option would be to turn off the _usetex when using a ScalarFormatter:
Complete example:
import matplotlib.pyplot as plt plt.rc( 'text', usetex=True ) plt.rc('font',family = 'sans-serif', size=20) fig , ax = plt.subplots(figsize=(5,3)) ax.set_xlabel( r'\textit{x} in a.u.' ) ax.set_ylabel( r'\textit{y} in a.u.' ) ax.xaxis.get_major_formatter()._usetex = False ax.yaxis.get_major_formatter()._usetex = False plt.tight_layout() plt.show()github-actions commented on Apr 10, 2023
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!