- 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
Matplotlib – How to set xticks and yticks with imshow plot?
63 Lectures 6 hours
To set xticks and yticks with imshow() plot, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Get the current axis.
- Create a random dataset.
- Display the data as an image, i.e., on a 2D regular raster.
- Set x and y ticks using set_xticks() and set_yticks() method.
- To display the figure, use show() method.
import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True ax = plt.gca() data = np.random.rand(6, 6) ax.imshow(data) # Set xticks and yticks ax.set_xticks([1, 2, 3, 4, 5]) ax.set_yticks([1, 2, 3, 4, 5]) plt.show()
It will produce the following output
- How to plot a Pandas multi-index dataFrame with all xticks (Matplotlib)?
- How to change xticks font size in a matplotlib plot?
- How to plot data into imshow() with custom colormap in Matplotlib?
- How to plot an image with non-linear Y-axis with Matplotlib using imshow?
- How can I plot NaN values as a special color with imshow in Matplotlib?
- How to draw a log-normalized imshow plot with a colorbar representing the raw data in Matplotlib?
- Adjusting gridlines and ticks in Matplotlib imshow
- How to add legend to imshow() in Matplotlib?
- Set two Matplotlib imshow plots to have the same colormap scale
- How to plot two dotted lines and set marker using Matplotlib?
- How to make xticks evenly spaced despite their values? (Matplotlib)
- How to give Matplolib imshow plot colorbars a label?
- How to plot and work with NaN values in Matplotlib?
- How to plot with xgboost.XGBCClassifier.feature_importances_ model? (Matplotlib)
- How to update matplotlib's imshow() window interactively?