# Fill colour in a scatter plot

6 ビュー (過去 30 日間)
Milan Kumar 2019 年 5 月 2 日

I neet to fill the graph for with light grey colour and remaining graph with a darker shade. Also two different pattern as backgrounds can also work.

サインインしてコメントする。

### 回答 (2 件)

Steven Lord 2024 年 7 月 9 日
This wasn't an option when the question was originally asked, but if you're using release R2023a or later you could use xregion (and similarly yregion for shaded regions in a range of Y values.)
x = 1:10;
plot(x, x.^2);
xregion([3 8], FaceColor = 'r')
yregion([-Inf 64; 9 Inf], FaceColor = 'c')
##### 0 件のコメント-2 件の古いコメントを表示-2 件の古いコメントを非表示

サインインしてコメントする。

SAI SRUJAN 2024 年 7 月 9 日
Hi Milan,
I understand that you are facing an issue to fill color in a scatter plot.
Please go through the following code sample to proceed further,
% Sample data
x = linspace(0, 10, 100);
y = 3*x + 5;
% Create scatter plot
scatter(x, y, 'b');
hold on;
x_fill1 = [x(x < 5) 5];
y_fill1 = [y(x < 5) 0];
x_fill2 = [5 x(x >= 5)];
y_fill2 = [0 y(x >= 5)];
% Fill the regions
fill(x_fill1, y_fill1, [0.8 0.8 0.8], 'FaceAlpha', 0.5);
fill(x_fill2, y_fill2, [0.5 0.5 0.5], 'FaceAlpha', 0.5);
hold off;
For a comprehensive understanding of the 'fill' function in MATLAB, please refer to the following documentation.
I hope this helps!

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

### Community Treasure Hunt

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

Start Hunting!

Translated by