# Squeeze some part of a plot

조회 수: 11 (최근 30일)
Lida 2024년 5월 2일
답변: Image Analyst 2024년 5월 3일
Hi, I'd like to squeze the above part of my plot so that the part after the break is 40% of the total y-axis and the below part is 60%. Is it possible to do that? Thank you very much.
##### 댓글 수: 4이전 댓글 2개 표시이전 댓글 2개 숨기기
MarKf 2024년 5월 3일
Oh I see I got the question wrong, sorry (I wasn't sure so I commented instead of answering). Thanks @Mathieu NOE.
Lida 2024년 5월 3일
I do not want to put the break. I want to squeeze the part above the break and strech the part below the break.

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

### 답변 (2개)

Abhishek Kumar Singh 2024년 5월 3일
Hi Lida,
I don't think MATLAB provides built-in functionality for such specific non-linear axis adjustments. But one can approximate this by manipulating the plot space visually. I got a resource from stackoverflow which might be helpful in your case:
Let's try this approach for a sine wave with amplitude 10. Assume the requirement of allocating 60% of the plot area to the range from 1 to 2, and 40% to the range from 2 to 10.
1. We need a piecewise function that maps the y-values from 1 to 2 to a larger range than the y-values from 2 to 10. Let's define a simple linear transformation for this purpose:
% Transformation function
% This is a conceptual function; the actual implementation may require adjustment
function y_transformed = transformY(y)
if y >= 1 && y <= 2
% Map 1-2 to a larger range, e.g., 0-6 for 60% of the plot area
y_transformed = (y - 1) * 3; % Adjust the scaling factor as needed
elseif y > 2 && y <= 10
% Map 2-10 to a smaller range, e.g., 6-10 for 40% of the plot area
y_transformed = (y - 2) * 0.5 + 6; % Adjust the scaling factor as needed
else
y_transformed = y; % For values outside 1-10, no transformation
end
end
2. Let's create a sine wave with an amplitude of 10 and apply the transformation to the y-values.
x = linspace(0, 2*pi, 1000); % Generate x values
y = 10 * sin(x); % Original sine wave
% Apply the transformation to y-values
y_transformed = arrayfun(@(y) transformY(y), y);
3. Now, plot the transformed data and adjust the y-axis ticks and labels to reflect the original scale.
plot(x, y_transformed);
ylim([0 10]); % Adjust based on the transformed scale
% Set custom y-ticks and labels to reflect the original y-values
yticks = 1:10; % Original y-tick values
yticklabels = arrayfun(@(y) sprintf('%d', y), yticks, 'UniformOutput', false);
set(gca, 'YTick', arrayfun(@(y) transformY(y), yticks), 'YTickLabel', yticklabels);
The transformation function transformY is conceptual and needs to be adjusted based on the exact visual requirement. The scaling factors were chosen to illustrate the approach and may not perfectly match the 60%/40% area distribution. Depending on your exact requirements, a more complex function (e.g., logarithmic for one range and linear for another) might be necessary.
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Lida 2024년 5월 3일

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

Image Analyst 2024년 5월 3일
There are several submissions in the File Exchange for broken y axes or axes with "gaps" in them. Search for "break y axis"

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

### 카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by