Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib: is a changing background color possible?

matplotlib python: How do you change the background color of a line plot according to a given column? Say I have the following data file

1. 0
4. 0
2. 0
1. 1
2. 1
3. 1
3. 2
1. 2
2. 2

The first column represents the y-values, and the 2nd column should control the background color. Say, it plots the (black) line on a white-gray alternating background (zebra-like) as proceeding further in x-direction, where the transition in color occurs anytime the integer in the 2nd column increments. Or other possible solution: Use 2nd column as function argument to determine background color.

How would one do this with matlibplot?

like image 256
ritter Avatar asked Jun 21 '11 14:06

ritter


People also ask

Can you change Python background color?

Right-click the upper-left corner of the Python console window and select Properties. In the dialog box that appears, pick the tab labeled Colors. On it you can set the screen background and text color.

How do you change the background color on a graph?

To change the background of your graph, click in the space between the plot area and the edge of your graph. Then, click the Drawing toolbar's Fill Color tool and select a color from the palette. As soon as you do, Excel changes the background of your chart, filling it with the color you selected.

How do you change the background color of a plot in Matlab?

a) From the File menu, select "Export setup". b) Under Properties select Rendering and check the “Custom color” option. c) Enter “w” in the adjacent text box and click “Apply to Figure” to update the figure. d) Use the “Edit -> copy figure” option to copy and paste the figure with white background in PowerPoint.


1 Answers

This one works:

    plt.axvspan(x, x2, facecolor='g', alpha=0.5)

where facecolor is the foreground color

like image 186
ritter Avatar answered Oct 28 '22 05:10

ritter