MATLAB Answers

0

How do I change location of the x axis of two scatter plots. I want x1 axis up and x2 axis down and y on the left of the plot

Lewis Asilevi さんによって質問されました 2018 年 3 月 15 日
最新アクティビティ Venkata Siva Krishna Madala さんによって 回答されました 2018 年 3 月 19 日
Hi all, Thank you in advance, I have to plot two scatter plots with different x axis values. I want the x axis values positioned up and down the plot and the y axis on the left as usual. I know in the normal plot function, changing the axis position is possible in the plot properties. However, I checked the scatter plot properties in the doc and it appears there is no such properties as axis position. When I try to find a way around this by using hold on, the first plot seems to be written over by the second. I need you assistance please. Here is my MWE
y = [0:20];
x1 = rand(1,length(y));
x2 = rand(1,length(y));
scatter(gca,x1,y,'MarkerFaceColor',[0 .7 .7],...
'LineWidth',1.5)
xlabel('x1');
ylabel('y');
set(gca,'XAxisLocation','bottom')
ax1 = gca;
set(ax1,'XAxisLocation','top')
hold on ax2 = axes('Position',get(ax1,'Position'),... 'XAxisLocation','top','XColor','k','YColor','k'); scatter(ax2,x2,y,'MarkerFaceColor',[0 1 0],... 'LineWidth',1.5) xlabel('x2'); ylabel('y'); hold off
Thank you.

  0 件のコメント

サインイン to comment.

1 件の回答

回答者: Venkata Siva Krishna Madala 2018 年 3 月 19 日

Hello Lewis Asilevi,
I understand your issue but after trying for a long time I have realised that there is no direct way of doing it. The only workaround I found is to do it this way :-
y = [0:20];
x1 = rand(1,length(y));
x2 = rand(1,length(y));
line(x1,y,'LineStyle','none','Marker','*')
ax1 = gca; % current axes
ax1.XColor = 'r';
ax1_pos = ax1.Position; % position of first axes
ax2 = axes('Position',ax1_pos,'XAxisLocation','top','Color','none');
line(x2,y,'Parent',ax2,'LineStyle','none','Marker','o')
Regards,
Krishna Madala

  0 件のコメント

サインイン to comment.



Translated by