![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 to change the color of a plot frame in Matplotlib?
To change the color of a plot frame, we can set axes ticklines and spine value into a specific color.
Steps
Create a figure and add a set of subplots, using subplots method with value 4.
Zip colors with axes and iterate them together.
In the iteration, set the color for spines values and ticklines (x, y).
Adjust the padding between and around the subplots.
To display the figure, use show() method.
Example
import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig, (ax1, ax2, ax3, ax4) = plt.subplots(4) for ax, color in zip([ax1, ax2, ax3, ax4], ['green', 'red', 'yellow', 'blue']): plt.setp(ax.spines.values(), color=color) ax.plot([8, 3], c=color) plt.setp([ax.get_xticklines(), ax.get_yticklines()], color=color) plt.show()
Output
Advertisements