Skip to main content

ConfPlot: Plot Confusion Matrix in Python

PyPI version CI

Plot a pretty confusion matrix (like Matlab) in python using seaborn and matplotlib

This module lets you plot a pretty looking confusion matrix from a np matrix or from a prediction results and actual labels.

Sample plots:

Getting started

Installation

pip install confplot

Usage

Plot confusion matrix from matrix

# import package
import confplot

# assume you have a confusion matrix array like this
array = np.array(
    [[13,  0,  1,  0,  2,  0],
     [ 0, 50,  2,  0, 10,  0],
     [ 0, 13, 16,  0,  0,  3],
     [ 0,  0,  0, 13,  1,  0],
     [ 0, 40,  0,  1, 15,  0],
     [ 0,  0,  0,  0,  0, 20]]
)

# convert it to a pandas dataframe
df_cm = DataFrame(array, index=range(1, 7), columns=range(1, 7))

# create and save confusion matrix plot as "cm_plot.png"
confplot.plot_confusion_matrix_from_matrix(df_cm, outfile="cm_plot.png")

Plot confusion matrix from data

# import package
import confplot

# assume you have 1D y_true (actual values) and y_pred (predictions) arrays
y_true = ...
y_pred = ...

# arange targetclass names if you want
columns = ["ahududu", "ananas", "armut", "avokado", "ayva"]

# create and save confusion matrix plot as "cm_plot.png"
confplot.plot_confusion_matrix_from_data(
    y_true,
    y_pred,
    columns,
    outfile="cm_plot.png"
)

Release files for confplot 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for confplot 0.1.1
File Size Uploaded
confplot-0.1.1.tar.gz 6.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for confplot 0.1.1
File Interpreter ABI Platform
confplot-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.0 kB

Release files / confplot-0.1.1.tar.gz

Download URL confplot-0.1.1.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
82a303da39228f57111457fc7acf217998591c8246f1313a37d54627e161d20e
BLAKE2b-256 checksum
How to use checksums
e2a34aea8faf2617fc868649cd592e534e8e93ad4dbd09bf389f8b4bb9986b8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

Release files / confplot-0.1.1-py3-none-any.whl

Download URL confplot-0.1.1-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cf476f102eb8edd73470bedc469ed52a1449c94ffe4c084287b7e5a618857aa6
BLAKE2b-256 checksum
How to use checksums
8949d45ceb0aa2061b15d3b143022f0669a30d33ba6bdcb38638be95f6e83f2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page