필터 지우기
필터 지우기

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.

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by