How to fill a 2D plot?
16 views (last 30 days)
Show older comments
close all
clear
clc
hold on
grid on
P_outside = ([0.1+0.6i,0.3+0.6i,0.4+0.8i,0.3+i,0+i,0+0.5i,0,0.1+0i,0.1+0.6i]);
P_inside = ([0.1+0.7i,0.21+0.7i,0.21+0.9i,0.1+0.9i,0.1+0.7i]);
plot(P_outside)
plot(P_inside)
xlim([-0.2,1])
ylim([-0.1,1])
I would like to fill the 'P' with a color, how do I do that?
0 Comments
Accepted Answer
Dave B
on 4 Nov 2021
Edited: Dave B
on 4 Nov 2021
You can use the fill function to fill a region. You can retrieve the x and y values using real and imag (I don't think fill does the same trick of splitting complex numbers like plot does)
P_outside = ([0.1+0.6i,0.3+0.6i,0.4+0.8i,0.3+i,0+i,0+0.5i,0,0.1+0i,0.1+0.6i]);
P_inside = ([0.1+0.7i,0.21+0.7i,0.21+0.9i,0.1+0.9i,0.1+0.7i]);
x=[real(P_outside) real(P_inside)];
y=[imag(P_outside) imag(P_inside)];
fill(x,y,'r','EdgeColor','none')
xlim([-0.2,1])
ylim([-0.1,1])
0 Comments
More Answers (0)
See Also
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!