- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 plot a confusion matrix with string axis rather than integer in Python?
To plot a confusion matrix with string axis rather than integer in Python, we can take the following steps−
- Make a list for labels.
- Create a confusion matrix. Use confusion_matrix() to calculate accuracy of classification.
- 3. Add an '~.axes.Axes' to the figure as part of a subplot arrangement.
- Plot the values of a 2D matrix or array as a color-coded image.
- Using colorbar() method, create a colorbar for a ScalarMappable instance, *mappable*
- 6. Set x and y ticklabels using set_xticklabels and set_yticklabels methods.
- To display the figure, use show() method.
Example
from matplotlib import pyplot as plt from sklearn.metrics import confusion_matrix plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True labels = ['business', 'health'] cm = confusion_matrix([3], [2]) fig = plt.figure() ax = fig.add_subplot(111) cax = ax.matshow(cm) fig.colorbar(cax) ax.set_xticklabels([''] + labels) ax.set_yticklabels([''] + labels) plt.show()
Output
- Related Articles
- How can I plot a confusion matrix in matplotlib?
- Python – Convert Integer Matrix to String Matrix
- How to plot a 2D matrix in Python with colorbar Matplotlib?
- How to create confusion matrix for a rpart model in R?
- How to display Matplotlib Y-axis range using absolute values rather than offset values?
- How to plot on secondary Y-Axis with Python Plotly?
- How to calculate the sensitivity and specificity from a confusion matrix in R?
- How to find the confusion matrix for linear discriminant analysis in R?
- How to set the Y-axis in radians in a Python plot?
- How to represent X-axis label of a bar plot with greater than equal to or less than equal to sign using ggplot2 in R?
- How to create matrix with random integer values in R?
- How to get integer values from a string in Python?
- How to convert an integer to a hexadecimal string in Python?
- How to convert an integer to a octal string in Python?
- Python – Rows with K string in Matrix

Advertisements