Why does line style in plot change?

7 visualizzazioni (ultimi 30 giorni)
Zahra
Zahra il 16 Mag 2013
Hi everybody
I made a scatterplot then I add a line on top of it. My problem is: The line style changed in the middle, it's really strange!!! I can not figure out why this happened. The following is my code: plot(x,y,'--','LineWidth',4,'color',[.5 .5 .5]);g
I would be so grateful, if someone could help me? Thanking you in advance Zara
Thank you very much for your quick answer. Yes, this command works properly with any random data. but when I apply on my data, this problem happen. I use R2012b. Perhaps there is something wrong in my data, Could this be the reason. I use data for sea ice thickness: x=[ 0 0.2009 0.2961 0.2919 0.2928 0.3333 0.3098 0.2702 0.2422 0.2245 0.2001 0.2988 0.2741 0.2871 0.3106 0.3172 0.2625 0.2555 0.2364 0.2565 0.2382 0.2123 0.2368 0.3267 0.3105 0.2599 0.3004 0.2620 0.2904 0.2962 0.2737 0.2892 0.2923 0.2773 0.2828 0.2366 0.2053 0.2466 0.2254 0.2370 0.2660 0.2098 0.2169 0.2119 0.2091 0.2278 0.2083 0.3022 0.2169 0.2044 0.2165 0.2191 0.2692 0.2493 0.2131 0.2407 0.2277 0.2936 0.2402 0.2009 0.2486 0.2467 0.2656 0.2595 0.5000 ] and y=0.1067x+0.643 Thank you Zara
Thanks a million dear Wayne King. I sort the vector x and now line style is ok. Thanks for your quick help. Zara

Risposte (3)

Wayne King
Wayne King il 16 Mag 2013
I do not get that behavior:
x = 1:100;
y = randn(100,1);
plot(x,y,'--','LineWidth',4,'color',[.5 .5 .5]);
Can you say more about what version of MATLAB you are using and what architecture?

Zahra
Zahra il 16 Mag 2013
Thank you very much for your quick answer. Yes, this command works properly with any random data. but when I apply on my data, this problem happen. I use R2012b. Perhaps there is something wrong in my data, Could this be the reason. I use data for sea ice thickness: x=[ 0 0.2009 0.2961 0.2919 0.2928 0.3333 0.3098 0.2702 0.2422 0.2245 0.2001 0.2988 0.2741 0.2871 0.3106 0.3172 0.2625 0.2555 0.2364 0.2565 0.2382 0.2123 0.2368 0.3267 0.3105 0.2599 0.3004 0.2620 0.2904 0.2962 0.2737 0.2892 0.2923 0.2773 0.2828 0.2366 0.2053 0.2466 0.2254 0.2370 0.2660 0.2098 0.2169 0.2119 0.2091 0.2278 0.2083 0.3022 0.2169 0.2044 0.2165 0.2191 0.2692 0.2493 0.2131 0.2407 0.2277 0.2936 0.2402 0.2009 0.2486 0.2467 0.2656 0.2595 0.5000 ] and y=0.1067x+0.643 Thank you Zara

Wayne King
Wayne King il 16 Mag 2013
That is because of the nature of your data. Your x-values are not equally spaced and they are not monotonic. Your x-values are best described as a random variable and hence your y values as well. You can see this clearly if you use scatter()
scatter(x,y)
You can see clearly in the scatter plot why your '--' does not render as you expect in the middle.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by