Matplotlib background shading based on array and color scheme

I wonder if it is possible to obscure the background of a typical matplotlib graph according to the displayed data.

For simplicity, let’s say, we have:

x=arange(1,5,0.01) y=sin(x) plot(x,y) 

Is it possible to darken the background of the axes based on the y value?

Shading can be achieved by passing an array containing x and y to imshow, for example:

 imshow(array, cmap='hot') 

although I want to have a line graph of x and y on top of this imshow figure.

Is it possible?

+4
source share
1 answer

I am sure that this is possible:

 x = arange(1,5,0.01) yarr = vstack((x,)) y = sin(x) imshow(yarr, extent=(min(x),max(x), min(y),max(y)), cmap=cm.hot) plot(x, y, color='cornflowerblue',lw=4) 

The keyword "degree" corresponds to image limitations on graphic data.

This will give you: this

+7
source

Source: https://habr.com/ru/post/1489238/


All Articles