Heatmap - number of decimal places on x-axis

5 ビュー (過去 30 日間)
M.G.
M.G. 2020 年 12 月 27 日
コメント済み: M.G. 2020 年 12 月 30 日
Hello everyone,
I've created a heatmap with x-axis values changing from 1.0 to 4.0 with the increment of 0.5. By default, these values are displayed on the x-axis as 1, 1.5, 2, 2.5 etc. Is there a way to change all of them to have one decimal place, i.e., 1.0, 1.5, 2.0, 2.5 etc.?

採用された回答

Adam Danz
Adam Danz 2020 年 12 月 29 日
編集済み: Adam Danz 2020 年 12 月 29 日
Similar to Walter Roberson's answer but does not require undocumented methods (and avoids the associated warning).
h = heatmap(__);
h.XDisplayLabels = compose('%.1f',str2double(h.XDisplayLabels));
  6 件のコメント
Adam Danz
Adam Danz 2020 年 12 月 29 日
編集済み: Adam Danz 2020 年 12 月 30 日
@Walter Roberson it's getting increasingly more difficult to remember all of the property names that essentially control the same components as other properties with the same name and this is especially true in the newer standalone visualization classes. XDisplayLabels in heatmap() is essentially the same as XTickLabel in virtually all other plotting functions. NumBins in scatterhistogram() is called NBins in scatterhist(). Grouped boxplots are created with boxplot(x,group) and uses 'symbol' to specify the outlier marker style but in boxchart groups are created with boxchart(group,x) and MarkerStyle is used to specify marker. I've come accross lots of these inconsistencies that develop a dependency on referencing the documentation.
Most of these inconsistencies should be fixed while allowing for backward compatibility; for example, 'NBins' could be documented while 'NumBins' could also be accepted.
M.G.
M.G. 2020 年 12 月 30 日
Thank you guys for your help. Now, my heatmap looks exactly like I wanted :)

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 12 月 27 日
編集済み: Walter Roberson 2020 年 12 月 27 日
https://www.mathworks.com/help/matlab/ref/xtickformat.html
'%.1f'
  2 件のコメント
M.G.
M.G. 2020 年 12 月 27 日
編集済み: M.G. 2020 年 12 月 27 日
Doesn't work with heatmap (see the screenshot below).
My experience with heatmaps tells me that for heatmaps everything is done differently than in the case of the other plots. That's why I started my topic highlighting it's about heatmap.
Walter Roberson
Walter Roberson 2020 年 12 月 29 日
Unfortunately the function that constructs the details of the chart is in a .p file so I cannot check the details.
What I find is that the Heatmap object that is generated has a hidden object XAxis which is a CategoricalRuler .
h = heatmap(appropriate arguments);
hs = struct(h); %a warning will be generated.
hs.XAxis.Categories = compose('%.1f', hs.XAxis.TickValues); %assign new cell array of labels

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

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by