You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ticklabels of horizontal colorbar not aligned when using text.usetex #11243
Bug summary
The positive and negative values of the major ticklabels in a horizontal colorbar are slightly shifted from the baseline when using text.usetex.
Code for reproduction
importnumpyasnpimportmatplotlib.pyplotaspltimportmatplotlibasmpl#### Un/Comment this part mpl.rcParams.update({'text.usetex': True})
####fig=plt.figure()
p=plt.imshow(np.random.random([20,20])-.5)
cb=plt.colorbar(p, orientation="horizontal")
plt.show()
Actual outcome
Expected outcome
The positive and negative values are on the same baseline in the default case (i.e. without text.usetex).
You can use \text{-} from latex->amsmath package instead of "-". The problem seems to be with the conventional latex rendering of "-" sign.
Try this code:-
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
plt.switch_backend('Qt5Agg')
mpl.rcParams.update({'text.usetex': True})
params = {'text.latex.preamble' : [r'\usepackage{amsmath}']}
plt.rcParams.update(params)
fig = plt.figure()
p=plt.imshow(np.random.random([20,20])-.5)
cb=plt.colorbar(p, orientation="horizontal")
labels = []
# Replace '-' with 'amsmath>> \text{-}'
for num in cb.ax.get_xticklabels():
num = num._text
labels.append(r'$\text{-}' + num[2:] if num[1] == '-' else r'' + num)
#print(labels)
cb.ax.set_xticklabels(labels)
plt.savefig('new.png')
plt.show()
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
avinashmnit30 commentedon May 29, 2018
You can use \text{-} from latex->amsmath package instead of "-". The problem seems to be with the conventional latex rendering of "-" sign.
Try this code:-
github-actions commentedon May 6, 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!
ksunden commentedon May 6, 2023
Appears to have been fixed by #16366 in mpl v3.3.0