Help! I want to add the percentage symbol (%) after the elevation label (ex: 1%, 3%, 5%) in a contour plot (photo attached). Is there any way to do this? I have read about clabel, but I am not sure it can do this. Thank you in advance!

 採用された回答

Yazan
Yazan 2021 年 7 月 4 日

0 投票

Use '%%' to write the '%' symbol:
fprintf('%%\n');

6 件のコメント

Ni Made Ayu Sinta Dewi
Ni Made Ayu Sinta Dewi 2021 年 7 月 4 日
Can you specify where I should add this to my program? It looks like this so far:
e=[10 5 3 1,10 5 3 1];
[C,h]=contour(X,Y,E,e,'ShowText','on','LineWidth',2.5);
xlabel('k_2/k_1')
ylabel('m_1/m_2')
grid on
grid minor
Thank you in advance!
Yazan
Yazan 2021 年 7 月 4 日
編集済み: Yazan 2021 年 7 月 4 日
Now I understand better what you are after. The following might help you
e=[10 5 3 1,10 5 3 1];
% do not show the text
[C,h] = contour(X,Y,E,e,'LineWidth',2.5);
xlabel('k_2/k_1')
ylabel('m_1/m_2')
grid on
grid minor
Then
ax = gca;
clabel(C);
allTxt = findobj(ax, 'Type', 'Text');
set(allTxt, {'String'}, append(get(allTxt, 'String'), '%'))
Ni Made Ayu Sinta Dewi
Ni Made Ayu Sinta Dewi 2021 年 7 月 4 日
This worked! Is it possible to put the label in the lines? Currently, the text is upright. I tried using clabel(C,h,e) where e=[10,5,3,1], but it produced an error. Thank you in advance!
Yazan
Yazan 2021 年 7 月 5 日
I am not sure how to make the labels follow the curvatures of the lines. I couldn't figure out how to have access to this feature. You still can rotate the labels easily by a given degree.
Ni Made Ayu Sinta Dewi
Ni Made Ayu Sinta Dewi 2021 年 7 月 6 日
Thank you anyway!
Yazan
Yazan 2021 年 7 月 6 日
Overall, I believe the best practice in your case is to just divide the levels by 100, as they are percentages, and keep the default level visualization by Matlab.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeContour Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by