change the hyphen (-) into minus sign (−, “U+2212”)

168 vues (au cours des 30 derniers jours)
SALEH ALHUMAID
SALEH ALHUMAID le 17 Juin 2022
Commenté : Zoltán le 27 Juin 2025
Hi,
How can I change the hyphen (-) into minus sign (−, “U+2212”) in Matlab plot!
the figure above generated from matlab which has the defalt minus sign. how can I change -20 -40 and -60 to −20 −40 and −60
  4 commentaires
Omri Davidson
Omri Davidson le 12 Jan 2023
You can also write the minus sign by using char(8722) with the regular tex interperter.
Walter Roberson
Walter Roberson le 12 Jan 2023
True. However, the original poster needs to use Latex, and Latex does not support unicode characters,

Connectez-vous pour commenter.

Réponse acceptée

Chunru
Chunru le 17 Juin 2022
set(groot,'defaultAxesTickLabelInterpreter','latex');
plot(randi([-60 60], [20, 1]))
xticks(-60:20:60)
yticklabels(strrep(yticklabels,'-','$-$'));
  3 commentaires
Haiyao Yu
Haiyao Yu le 20 Jan 2023
If you use tex as the format control, you can run the following command alone, note that the first is a hyphen, and the second is a minus sign.
xticklabels(strrep(xticklabels,'-','–'));
yticklabels(strrep(yticklabels,'-','–'));
Chien-Han Su
Chien-Han Su le 8 Fév 2023
Thanks too!

Connectez-vous pour commenter.

Plus de réponses (3)

Walter Roberson
Walter Roberson le 17 Juin 2022
Modifié(e) : Walter Roberson le 12 Jan 2023
plot(randi([-60 60], [20, 1]))
xticks(-60:20:60)
set(gca, 'TickLabelInterpreter', 'latex')
ytickformat('$%g$')
  4 commentaires
Walter Roberson
Walter Roberson le 23 Août 2022
[cmat, h] = contour(....);
clabel(cmat, h);
set(h.TextPrims, 'Interpreter', 'latex');
Have a look at that and see if it does what you need. If not, then it might be necessary to modify the h.TextPrims 'String' properties.
Zoltán
Zoltán le 27 Juin 2025
This answer is better than the accepted one, because manually calling yticklabels() freezes the labels and they won't update when zooming.

Connectez-vous pour commenter.


Changliang Xiong
Changliang Xiong le 23 Août 2022
I recommend to save the .fig as *.pdf.Then,adobe illustrator could be used to directly modify the sign.

Jan Kelner
Jan Kelner le 30 Jan 2024
Is it possible to change the 'hyphen' to 'minus' sign in the heatmap values and colorbar scale values?

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by