- Trending Categories
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
Changing the color of an axis in Matplotlib
First, we can get the axes. Then, ax.spines could help to set the color by specifying the name of the axes, i.e., top, bottom, right and left.
Steps
Add an axes to the current figure and make it the current axes.
Using step 1 axes, we can set the color of all the axes.
Using ax.spines[axes].set_color(‘color’), set the color of the axes. Axes could be bottom, top, right, and left. Color could be yellow, red, black, and blue.
To show the figure, use the plt.show() method.
Example
from matplotlib import pyplot as plt ax = plt.axes() ax.spines['bottom'].set_color('yellow') ax.spines['top'].set_color('red') ax.spines['right'].set_color('black') ax.spines['left'].set_color('blue') plt.show()
Output
- Related Articles
- Changing the color of a single X-axis tick label in Matplotlib
- Changing the formatting of a datetime axis in Matplotlib
- Changing color randomly in JavaScript
- How to change the color of the axis, ticks and labels for a plot in matplotlib?
- How to set the unit length of an axis in Matplotlib?
- How to draw a line outside of an axis in Matplotlib?
- Show tick labels when sharing an axis in Matplotlib
- Preserve padding while setting an axis limit in matplotlib
- Changing the color a Tkinter rectangle on clicking
- Changing the color and marker of each point using Seaborn jointplot
- Changing the background color of a tkinter window using colorchooser module
- How to change the range of the X-axis and Y-axis in Matplotlib?
- How can I get the length of a single unit on an axis in Matplotlib?
- Using Colormaps to set the color of line in Matplotlib
- How to Adjust the Position of Axis Labels in Matplotlib?

Advertisements