- 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
How to change the color of the ticks in the colorbar in Matplotlib?
To change the color of the ticks in the colorbar in matplotlib, we can take the following steps−
- Create a random 2D−Array using numpy, with 4☓4 dimension.
- Use imshow() method to display the data as an image.
- Create a colorbar using colorbar() method with scalar mappable instance of imshow().
- Use getp() method to return the value of an object's property or print all of them.
- Set the property of an artist object.
- To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.rand(4, 4) im = plt.imshow(data, cmap="twilight_shifted_r") cbar = plt.colorbar(im) cbar_yticks = plt.getp(cbar.ax.axes, 'yticklabels') plt.setp(cbar_yticks, color='r') plt.show()
Output
- Related Articles
- How to add Matplotlib Colorbar Ticks?
- How to change the color of the axis, ticks and labels for a plot in matplotlib?
- How to change the spacing between ticks in Matplotlib?
- How to change the axis ticks color in base R plot?
- How to change the font properties of a Matplotlib colorbar label?
- How to animate the colorbar in Matplotlib?
- How to change the color of a plot frame in Matplotlib?
- How to change the text color of font in the legend using Matplotlib?
- How can I change the font size of ticks of axes object in Matplotlib?
- How to change the color of a line using radiobuttons in Matplotlib?
- How to shift the colorbar position to right in matplotlib?
- How to set the number of ticks in plt.colorbar in Matplotlib?
- How to change the face color of a plot using Matplotlib?
- How to change axes background color in Matplotlib?
- How to change the plot line color from blue to black in Matplotlib?

Advertisements