- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I set the background color on specific areas of a Pyplot figure using Matplotlib?
To set the background color on specific areas of a pyplot, we can take the following steps −
Using subplots() method, create a figure and a set of subplots, where nrows=1.
Using rectangle, we can create a rectangle, defined via an anchor point and its width and height. Where, edgecolor=orange, linewidth=7, and facecolor=green.
To plot a diagram over the axis, we can create a line using plot() method, where line color is red.
To color a specific portion of the plot, add a rectangle patch on the diagram using add_patch() method.
To display the figure, use show() method.
from matplotlib import pyplot as plt, patches plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True figure, ax = plt.subplots(1) rectangle = patches.Rectangle((2, 4), 3, 3, edgecolor='orange', facecolor="green", linewidth=7) ax.plot([2, 4, 5, 1, 4, 8, 0], c='red') ax.add_patch(rectangle) plt.show()
- How can I attach a pyplot function to a figure instance? (Matplotlib)
- How can I get the color of the last figure in Matplotlib?
- How can I get pyplot images to show on a console app? (Matplotlib)
- How to set the background color of a column in a matplotlib table?
- How to set the margins of a Matplotlib figure?
- How can we set the background color to a JPanel in Java?
- How to set the background color of selection of Ellipse using FabricJS?
- How to get the list of axes for a figure in Pyplot?
- How can we set a background color to JSplitPane in Java?
- How do I close all the open pyplot windows (Matplotlib)?
- How to set the current figure in Matplotlib?
- How to set the background color of a ttk.Combobox in tkinter?
- How do I set color to Rectangle in Matplotlib?
- How can I dynamically update my Matplotlib figure as the data file changes?
- How do I get the background color of a Tkinter Canvas widget?