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?
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.
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.
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.
This one works:
plt.axvspan(x, x2, facecolor='g', alpha=0.5)
where facecolor is the foreground color
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With