plotting issue along the x-axis !
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hello ! I would like to plot two curves in the same figure, to make my issue more clear let consider the following example:
x = linspace(0,10,20);
y = x ;
y1 = x;
plot(x,y);hold on
plot(-x,y1) ;
I would like to get the same general aspect of the figure but with the second curve plotted along [10 0], any suggestions how can I get it done ?! Thank you!
채택된 답변
Star Strider
2017년 12월 9일
Use fliplr (or flip) on the x argument in the second plot call:
x = linspace(0,10,20);
y = x ;
y1 = x;
plot(x,y)
hold on
plot(fliplr(x),y1)
hold off
댓글 수: 8
Ano
2017년 12월 9일
thank you for your answer but it didn't work , actually I would like to have an x-axis along [0 10] but with two directions as showing in the figure attached

Star Strider
2017년 12월 9일
편집: Star Strider
2017년 12월 11일
The easiest way is to simply re-label the x-axis:
x = linspace(0,10,20);
y = x ;
y1 = x;
plot(x,y)
hold on
plot(-x,y1)
hold off
set(gca, 'XTickLabel', [10:-2:0 2:2:10])
EDIT —
Another option:
x = linspace(0,10,20);
y = x ;
y1 = x;
plot(x,y)
hold on
plot(-x,y1)
hold off
xt = get(gca, 'XTick');
lxt = length(xt);
set(gca, 'XTickLabel', [-(xt(1:fix(lxt/2))) xt(fix(lxt/2)+1:end)])
The second option is robust to the values of ‘xt’.
Ano
2017년 12월 11일
thank you very much for your reply! the second option outputted the x-axis without any scale. I wanted to know how can I keep the same figure with all the specifications but to plot y1= x and not y1 = -x , any suggestions?
I have no idea what you want to do.
Try this:
x = linspace(-10,10,21);
y = abs(x);
plot(x,y)
xt = get(gca, 'XTick');
lxt = length(xt);
set(gca, 'XTickLabel', [-(xt(1:fix(lxt/2))) xt(fix(lxt/2)+1:end)])
Ano
2017년 12월 11일
thanks it works ! the general idea that I would like to learn how to do is how can I divide my figure (subplot is not what I mean here) so that I will get from the center to the Left plot var1 , and from the center to the right plot var2 , is it clear now to you what I what to do ?!
In the code in my previous Comment, I used the same function plotted over the negative and positive axes, and then took the absolute value of it and re-labeled the x-axis.
If you want to plot two different functions on the same axes, you can do what I did here (plot the absolute value of the second function over the negative axis), then re-label the axes.
Plotting the absolute value of the second function and then re-labeling the axes appears to be the result you want.
Example —
x = linspace(-2.1, 10, 51);
y1 = x;
y2 = abs(x).^3;
figure(1)
plot(x(x>=0), y1(x>=0))
hold on
plot(x(x<=0), y2(x<=0))
hold off
xt = get(gca, 'XTick');
lxt = length(xt);
set(gca, 'XTickLabel', [-(xt(1:fix(lxt/2))) xt(fix(lxt/2)+1:end)])
This appears to be reasonably robust.
Ano
2017년 12월 11일
thank you very much !
Star Strider
2017년 12월 11일
As always, my pleasure!
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
