Skip to main content

Python package to easily make barplots from multi-indexed dataframes.

Project description

Travis CI build SonarCloud Quality SonarCloud Maintainability Codacy Maintainability Maintainability Pypi project Pypi total project downloads

Python package to easily make barplots from multi-indexed dataframes.

How do I install this package?

As usual, just download it using pip:

pip install barplots

Tests Coverage

Since some software handling coverages sometime get slightly different results, here’s three of them:

Coveralls Coverage SonarCloud Coverage Code Climate Coverate

Documentation

Most methods, in particular those exposed to user usage, are provided with doc strings. Consider reading these docstrings for learning the most recent updates to the library.

Usage examples

Here follows a set of examples of common usages. Basically, every graph show either the same data or a mean based on the provided group by indices. Choose whetever representation is best for visualizing your data, as hardly one is better than another for every possible dataset.

N.B. The data used in the following examples are randomly generated so to be useful for test porposes. DO NOT consider these values as valid results for experiments using the same labels (cell lines etc…) which are only used to show possible usages.

For every example, the considered dataframe df is loaded as follows:

import pandas as pd

df = pd.read_csv("tests/test_case.csv")

Also, for every example, the custom_defaults used to sanitize the labels specific to the used dataset is:

custom_defaults = {
    "P": "promoters",
    "E": "enhancers",
    "A": "active ",
    "I": "inactive ",
    "+": " and ",
    "": "anything",
    "Validation":"val"
}

Horizontal Example A

In the following example we will plot the bars horizontally, rotating the group labels by 90 degrees and displaying the bar labels as a shared legend.

from barplots import barplots

barplots(
    df,
    groupby=["task","model"],
    orientation="horizontal",
    show_legend=True,
    minor_rotation=90,
    custom_defaults=custom_defaults
)

Result can be seen here.

Horizontal Example B

In the following example we will plot the top index as multiple subplots with horizontal bars, rotating the group labels by 90 degrees and displaying the bar labels as a shared legend.

from barplots import barplots

barplots(
    df,
    groupby=["cell_line", "task","model"],
    orientation="horizontal",
    show_legend=True,
    subplots=True,
    minor_rotation=90,
    custom_defaults=custom_defaults
)
https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/horizontal_legend_subplots_minor_rotation_val_auroc.png?raw=true

Horizontal Example C

In the following example we will plot horizontal bars, rotating the top group labels by 90 degrees and displaying the bar labels as minor ticks.

from barplots import barplots

barplots(
    df,
    groupby=["task","model"],
    orientation="horizontal",
    show_legend=False,
    major_rotation=90,
    custom_defaults=custom_defaults
)

Result can be seen here

Horizontal Example D

In the following example we will plot the top index as multiple subplots with horizontal bars, rotating the group labels by 90 degrees and displaying the bar labels as minor ticks.

from barplots import barplots

barplots(
    df,
    groupby=["cell_line", "task","model"],
    orientation="horizontal",
    show_legend=False,
    major_rotation=90,
    subplots=True,
    custom_defaults=custom_defaults
)
https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/horizontal_subplots_major_rotation_val_auroc.png?raw=true

Vertical Example A

In the following example we will plot the bars vertically and displaying the bar labels as a shared legend.

from barplots import barplots

barplots(
    df,
    groupby=["task","model"],
    orientation="vertical",
    show_legend=True,
    custom_defaults=custom_defaults
)

Result can be seen here

Vertical Example B

In the following example we will plot the top index as multiple subplots with vertical bars and displaying the bar labels as a shared legend.

from barplots import barplots

barplots(
    df,
    groupby=["cell_line", "task","model"],
    orientation="vertical",
    show_legend=True,
    subplots=True,
    custom_defaults=custom_defaults
)
https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/vertical_legend_subplots_val_auroc.png

Vertical Example C

In the following example we will plot vertical bars, rotating the minor group labels by 90 degrees and displaying the bar labels as minor ticks.

from barplots import barplots

barplots(
    df,
    groupby=["task","model"],
    orientation="vertical",
    show_legend=False,
    minor_rotation=90,
    custom_defaults=custom_defaults
)

Result can be seen here

Vertical Example D

In the following example we will plot the top index as multiple subplots with vertical bars, rotating the minor group labels by 90 degrees and displaying the bar labels as minor ticks.

from barplots import barplots

barplots(
    df,
    groupby=["cell_line", "task","model"],
    orientation="vertical",
    show_legend=False,
    minor_rotation=90,
    subplots=True,
    custom_defaults=custom_defaults
)
https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/vertical_subplots_minor_rotation_val_auroc.png

Future features

Currently it is not possible to automatically detect labels overlap and rotate them. I will work on this feature when I get the time, currently you will need to use the parameters minor_rotation and major_rotation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

barplots-1.1.8.tar.gz (13.6 kB view details)

Uploaded Source

File details

Details for the file barplots-1.1.8.tar.gz.

File metadata

  • Download URL: barplots-1.1.8.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.7.6

File hashes

Hashes for barplots-1.1.8.tar.gz
Algorithm Hash digest
SHA256 4abe74276b0c4dcc64272e54ad331cef599158273e09a86355ff0e38e16be293
MD5 91f722d67f0d06a3955942b546b72432
BLAKE2b-256 420317123ea180d4a694bd0b02acda359f7dd4683a2fd86d7d2430ce0a3ee470

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page