Plot with background colors depending on the y values

This is my data
data = [1 2 3 4 5 6 7 8 9 10 ; 0.2 0.5 0.1 0.02 0.04 3 6 7 0.01 0.05];
In fact, I have a similar data frame but with a large amount of values (it is about 25 000 rows and 2 columns (x and y))
And I want to obtain this graph in which the background color depends on the yvalue (here : blue for yvalue < 1 and brown for yvalue > 1)
Thanks for help !

답변 (1개)

KSSV
KSSV 2017년 10월 12일
data = [1 2 3 4 5 6 7 8 9 10 ; 0.2 0.5 0.1 0.02 0.04 3 6 7 0.01 0.05];
x = data(1,:) ; y = data(2,:) ;
[X,Y] = meshgrid(x,y) ;
pcolor(X,Y,Y) ; shading interp
hold on
plot(x,y,'b')

댓글 수: 4

It is not really that I want
To rephrase : I want to attribute, to each x value, a specific color which depends on the y value
KSSV
KSSV 2017년 10월 12일
The code does what you shown in image...why don't you show a pictorial example of what you expect.
You can also use patch() or fill() in place of pcolor().
I got it ! But I used bar() (to create histogram) instead of patch() or pcolor()

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

질문:

2017년 10월 12일

댓글:

2017년 10월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by