- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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 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.
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.
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()
- Related Articles
- How can I plot hysteresis threshold in Matplotlib?
- How can I plot a single point in Matplotlib Python?
- How to plot a confusion matrix with string axis rather than integer in Python?
- How can I place a table on a plot in Matplotlib?
- How can I make a scatter plot colored by density in Matplotlib?
- Can I give a border to a line in Matplotlib plot function?
- How can I plot NaN values as a special color with imshow in Matplotlib?
- How to plot an animated image matrix in matplotlib?
- How to plot a 2D matrix in Python with colorbar Matplotlib?
- How do I plot only a table in Matplotlib?
- How can I get the output of a Matplotlib plot as an SVG?
- How can I plot two different spaced time series on one same plot in Python Matplotlib?
- How to create confusion matrix for a rpart model in R?
- How can I make the xtick labels of a plot be simple drawings using Matplotlib?
- How do I plot a step function with Matplotlib in Python?