# How to put a variable YTICK

조회 수: 4(최근 30일)
Alejandro Fernández 2019년 11월 28일
댓글: Alejandro Fernández 2019년 11월 28일
Hello, everybody. The doubt I have is the following:
With the code that I attach at the bottom I get the graphic that I also attach. The thing is that in theY-axis I would like to put a label with the number that is really representing. The problem is that I want to do it depending on the value of the line. In other words, I don't want to manually put a fixed value in the middle of the yticks because it will change.
The code is adapted and the original source is this: ORIGINAL CODE
close all
% Create plotting data and plot
x = 0:254; y = Z(:,:,1);
plot(x,y,'LineWidth',3)
hold on
plot(x,min(y)*ones(length(x)),'r--','LineWidth',2)
% yticks([min(y)])
hold off
xlim([0 255])
ylim([6.5 7])
ylabel('Valor del promedio [\mum]')
xticks(linspace(0,255,16))
% Get current axes object (just plotted on) and its position
ax1 = gca;
axPos = ax1.Position;
% Change the position of ax1 to make room for extra axes
% format is [left bottom width height], so moving up and making shorter here...
ax1.Position = axPos + [0 0.2 -0 -0.2];
% Exactly the same as for plots (above), axes LineWidth can be changed inline or after
ax1.LineWidth = 2;
title('Representación de la evolución del Promedio para Canny con TH_{MIN}=0.4\cdotTH_{MAX}')
grid on
% Add two more axes objects, with small multiplier for height, and offset for bottom
ax2 = axes('position', (axPos .* [1 1 1 1e-3]) + [0 0.1 0 0], 'color', 'none', 'linewidth', 2);
% You can change the limits of the new axes using XLim
ax2.XLim = [0 255*0.4];
ax2.XTick = (linspace(0,255*0.4,18));
% You can label the axes using XLabel.String
ax1.XLabel.String = 'Threshold Máximo';
ax2.XLabel.String = 'Threshold Mínimo';

댓글을 달려면 로그인하십시오.

### 답변(1개)

Image Analyst 2019년 11월 28일
Try
yticks(yourVariable);
##### 댓글 수: 9표시숨기기 이전 댓글 수: 8
Alejandro Fernández 2019년 11월 28일
Ok. Thank you.

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!

Translated by