 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
How can I 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
 