フィルターのクリア

Change Number of Decimal Places on Y-Axis Tick Labels on Scatter Plot

5 ビュー (過去 30 日間)
AmericanExpat26
AmericanExpat26 2016 年 9 月 9 日
コメント済み: Star Strider 2016 年 9 月 10 日
I am producing a series of scatter plots for a scientific publication and I am trying to change the number of decimal places associated with the tick labels on the y-axis, so that it displays 4 at each increment. Lines of code of interest given below.
ylim([-0.4500 -0.4300])
ytix = get(gca,'ytick')
set(gca,'yticklabel',sprintf('%.4f',ytix));
The values of y-axis tick labels are now indeed include the desired 4 decimal places, but when trying to set the new labels, the entire matrix appears at each tick mark, instead of the appropriate single value. A screenshot of the plot is included.
Any help on how to solve the problem of getting only the right displayed at each tick mark would be appreciated.
-AmericanExpat26

回答 (1 件)

Star Strider
Star Strider 2016 年 9 月 10 日
You need to create a cell array for the y-tick labels, and split each into a separate element of the cell array. Add a separate assignment to generate the labels, and then write all but the last label (which is blank) to 'YTickLabel':
ytixlbl = regexp(sprintf('%.4f\n',ytix), '\n', 'split');
set(gca,'yticklabel',ytixlbl(1:end-1))
You can do the same thing with the strsplit function as with the regexp call, but not everyone has strsplit.
  2 件のコメント
AmericanExpat26
AmericanExpat26 2016 年 9 月 10 日
Many thanks for the help.
Star Strider
Star Strider 2016 年 9 月 10 日
My pleasure.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by