
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Plot a Confusion Matrix in Matplotlib
Using imshow method, we can create an image with an input (5, 5) array dimension. After that, we can use the xticks and yticks method to mark the ticks on the axes.
Steps
Return random floats in the half-open interval [5, 5) and interpolation='nearest'.
Display data as an image, i.e., on a 2D regular raster, with step 1 data.
Get or set the current tick locations and labels of the X-axis, using xticks method.
Get or set the current tick locations and labels of the Y-axis, using yticks method.
Use plt.show() to show the figure.
Example
import matplotlib.pyplot as plt import numpy as np plt.imshow(np.random.random((5, 5)), interpolation='nearest') plt.xticks(np.arange(0, 5), ['A', 'B', 'C', 'D', 'E']) plt.yticks(np.arange(0, 5), ['1', '2', '3', '4', '5']) plt.show()
Output
Advertisements