# Barplots
[![pip](https://badge.fury.io/py/barplots.svg)](https://pypi.org/project/barplots/)
[![downloads](https://pepy.tech/badge/barplots)](https://pepy.tech/project/barplots)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/LucaCappelletti94/barplots/blob/master/LICENSE)
[![CI](https://github.com/LucaCappelletti94/barplots/actions/workflows/python.yml/badge.svg)](https://github.com/LucaCappelletti94/barplots/actions)
Python package to easily make barplots from multi-indexed dataframes.
## How do I install this package?
As usual, just download it using pip:
```shell
pip install barplots
```
## Documentation
Most methods, in particular those exposed to user usage, are provided with docstrings. Consider reading these docstrings to learn about the most recent updates to the library.
## Examples of the DataFrame structure
The dataframe to be provided to the barplots library may look like the following:
| miss_rate | fall_out | mcc | evaluation_type | unbalance | graph_name | normalization_name |
|------------|----------|-----------|-----------------|-----------|----------------------------|--------------------|
| 0.0332031 | 0.705078 | 0.353357 | train | 10 | AlligatorSinensis | Traditional |
| 0.240234 | 0.478516 | 0.289591 | train | 1 | CanisLupus | Right Laplacian |
| 0.0253906 | 0.931641 | 0.101643 | train | 100 | AlligatorSinensis | Right Laplacian |
| 0.121094 | 0.699219 | 0.220219 | train | 10 | HomoSapiens | Traditional |
| 0.0136719 | 0.292969 | 0.722095 | test | 1 | CanisLupus | Right Laplacian |
| 0.0605469 | 0.90625 | 0.0622185 | test | 10 | AmanitaMuscariaKoideBx008 | Traditional |
| 0.0078125 | 0.4375 | 0.614287 | train | 100 | AmanitaMuscariaKoideBx008 | Traditional |
| 0.171875 | 0.869141 | -0.0572194| train | 100 | AlligatorSinensis | Traditional |
| 0.0859375 | 0.810547 | 0.150206 | train | 10 | MusMusculus | Right Laplacian |
| 0.0273438 | 0.646484 | 0.415357 | test | 10 | MusMusculus | Right Laplacian |
Specifically, in this example, we may create bar plots for the features **Miss rate**, **fallout**, and **Matthew Correlation Coefficient** by grouping on the `evaluation_type`, `unbalance`, `graph_name`, and `normalization_name` columns.
An example CSV file can be seen [here](https://github.com/LucaCappelletti94/barplots/blob/master/tests/test_case.csv).
## Usage examples
Here follows a set of examples of common usages. Basically, every graph shows either the same data or a mean based on the provided group by indices. Choose whatever representation is best for visualizing your data, as one is not necessarily better than another for every dataset.
> **Note**: The data used in the following examples are **randomly generated** for testing purposes. **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:
```python
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 dataset is:
```python
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.
```python
from barplots import barplots
import pandas as pd
df = pd.read_csv("tests/test_case.csv")
custom_defaults = {
"P": "promoters",
"E": "enhancers",
"A": "active ",
"I": "inactive ",
"+": " and ",
"": "anything",
"Validation": "val"
}
barplots(
df,
groupby=["task", "model"],
orientation="horizontal",
show_legend=True,
minor_rotation=90,
custom_defaults=custom_defaults
)
```
Result can be seen [here](https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/horizontal_legend_minor_rotation_val_auroc.png?raw=true).
### Horizontal Example B
In this 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.
```python
from barplots import barplots
import pandas as pd
df = pd.read_csv("tests/test_case.csv")
custom_defaults = {
"P": "promoters",
"E": "enhancers",
"A": "active ",
"I": "inactive ",
"+": " and ",
"": "anything",
"Validation": "val"
}
barplots(
df,
groupby=["cell_line", "task", "model"],
orientation="horizontal",
show_legend=True,
subplots=True,
minor_rotation=90,
custom_defaults=custom_defaults
)
```
![Horizontal Example B](https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/horizontal_legend_subplots_minor_rotation_val_auroc.png?raw=true)
### Horizontal Example C
In this example, we will plot horizontal bars, rotating the top group labels by 90 degrees, and displaying the bar labels as minor ticks.
```python
from barplots import barplots
import pandas as pd
df = pd.read_csv("tests/test_case.csv")
custom_defaults = {
"P": "promoters",
"E": "enhancers",
"A": "active ",
"I": "inactive ",
"+": " and ",
"": "anything",
"Validation": "val"
}
barplots(
df,
groupby=["task", "model"],
orientation="horizontal",
show_legend=False,
major_rotation=90,
custom_defaults=custom_defaults
)
```
Result can be seen [here](https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/horizontal_major_rotation_val_auroc.png?raw=true).
### Horizontal Example D
In this 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.
```python
from barplots import barplots
import pandas as pd
df = pd.read_csv("tests/test_case.csv")
custom_defaults = {
"P": "promoters",
"E": "enhancers",
"A": "active ",
"I": "inactive ",
"+": " and ",
"": "anything",
"Validation": "val"
}
barplots(
df,
groupby=["cell_line", "task", "model"],
orientation="horizontal",
show_legend=False,
major_rotation=90,
subplots=True,
custom_defaults=custom_defaults
)
```
![Horizontal Example D](https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/horizontal_subplots_major_rotation_val_auroc.png?raw=true)
### Vertical Example A
In this example, we will plot the bars vertically and display the bar labels as a shared legend.
```python
from barplots import barplots
import pandas as pd
df = pd.read_csv("tests/test_case.csv")
custom_defaults = {
"P": "promoters",
"E": "enhancers",
"A": "active ",
"I": "inactive ",
"+": " and ",
"": "anything",
"Validation": "val"
}
barplots(
df,
groupby=["task", "model"],
orientation="vertical",
show_legend=True,
custom_defaults=custom_defaults
)
```
Result can be seen [here](https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/vertical_legend_val_auroc.png).
### Vertical Example B
In this example, we will plot the top index as multiple subplots with vertical bars, displaying the bar labels as a shared legend.
```python
from barplots import barplots
import pandas as pd
df = pd.read_csv("tests/test_case.csv")
custom_defaults = {
"P": "promoters",
"E": "enhancers",
"A": "active ",
"I": "inactive ",
"+": " and ",
"": "anything",
"Validation": "val"
}
barplots(
df,
groupby=["cell_line", "task", "model"],
orientation="vertical",
show_legend=True,
subplots=True,
custom_defaults=custom_defaults
)
```
![Vertical Example B](https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/vertical_legend_subplots_val_auroc.png)
### Vertical Example C
In this example, we will plot vertical bars, rotating the minor group labels by 90 degrees, and displaying the bar labels as minor ticks.
```python
from barplots import barplots
import pandas as pd
df = pd.read_csv("tests/test_case.csv")
custom_defaults = {
"P": "promoters",
"E": "enhancers",
"A": "active ",
"I": "inactive ",
"+": " and ",
"": "anything",
"Validation": "val"
}
barplots(
df,
groupby=["task", "model"],
orientation="vertical",
show_legend=False,
minor_rotation=90,
custom_defaults=custom_defaults
)
```
Result can be seen [here](https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/vertical_minor_rotation_val_auroc.png).
### Vertical Example D
In this 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.
```python
from barplots import barplots
import pandas as pd
df = pd.read_csv("tests/test_case.csv")
custom_defaults = {
"P": "promoters",
"E": "enhancers",
"A": "active ",
"I": "inactive ",
"+": " and ",
"": "anything",
"Validation": "val"
}
barplots(
df,
groupby=["cell_line", "task", "model"],
orientation="vertical",
show_legend=False,
minor_rotation=90,
subplots=True,
custom_defaults=custom_defaults
)
```
![Vertical Example D](https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/vertical_subplots_minor_rotation_val_auroc.png)
Raw data
{
"_id": null,
"home_page": "https://github.com/LucaCappelletti94/barplots",
"name": "barplots",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Luca Cappelletti",
"author_email": "cappelletti.luca94@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/9a/fd/563e5aca5b8ee15619e50e15de133fec0c9fcfbc72ea8add7bef5d97c2fb/barplots-1.2.1.tar.gz",
"platform": null,
"description": "# Barplots\n\n[![pip](https://badge.fury.io/py/barplots.svg)](https://pypi.org/project/barplots/)\n[![downloads](https://pepy.tech/badge/barplots)](https://pepy.tech/project/barplots)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/LucaCappelletti94/barplots/blob/master/LICENSE)\n[![CI](https://github.com/LucaCappelletti94/barplots/actions/workflows/python.yml/badge.svg)](https://github.com/LucaCappelletti94/barplots/actions)\n\nPython package to easily make barplots from multi-indexed dataframes.\n\n## How do I install this package?\n\nAs usual, just download it using pip:\n\n```shell\npip install barplots\n```\n\n## Documentation\n\nMost methods, in particular those exposed to user usage, are provided with docstrings. Consider reading these docstrings to learn about the most recent updates to the library.\n\n## Examples of the DataFrame structure\n\nThe dataframe to be provided to the barplots library may look like the following:\n\n| miss_rate | fall_out | mcc | evaluation_type | unbalance | graph_name | normalization_name |\n|------------|----------|-----------|-----------------|-----------|----------------------------|--------------------|\n| 0.0332031 | 0.705078 | 0.353357 | train | 10 | AlligatorSinensis | Traditional |\n| 0.240234 | 0.478516 | 0.289591 | train | 1 | CanisLupus | Right Laplacian |\n| 0.0253906 | 0.931641 | 0.101643 | train | 100 | AlligatorSinensis | Right Laplacian |\n| 0.121094 | 0.699219 | 0.220219 | train | 10 | HomoSapiens | Traditional |\n| 0.0136719 | 0.292969 | 0.722095 | test | 1 | CanisLupus | Right Laplacian |\n| 0.0605469 | 0.90625 | 0.0622185 | test | 10 | AmanitaMuscariaKoideBx008 | Traditional |\n| 0.0078125 | 0.4375 | 0.614287 | train | 100 | AmanitaMuscariaKoideBx008 | Traditional |\n| 0.171875 | 0.869141 | -0.0572194| train | 100 | AlligatorSinensis | Traditional |\n| 0.0859375 | 0.810547 | 0.150206 | train | 10 | MusMusculus | Right Laplacian |\n| 0.0273438 | 0.646484 | 0.415357 | test | 10 | MusMusculus | Right Laplacian |\n\nSpecifically, in this example, we may create bar plots for the features **Miss rate**, **fallout**, and **Matthew Correlation Coefficient** by grouping on the `evaluation_type`, `unbalance`, `graph_name`, and `normalization_name` columns.\n\nAn example CSV file can be seen [here](https://github.com/LucaCappelletti94/barplots/blob/master/tests/test_case.csv).\n\n## Usage examples\n\nHere follows a set of examples of common usages. Basically, every graph shows either the same data or a mean based on the provided group by indices. Choose whatever representation is best for visualizing your data, as one is not necessarily better than another for every dataset.\n\n> **Note**: The data used in the following examples are **randomly generated** for testing purposes. **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.\n\nFor every example, the considered dataframe `df` is loaded as follows:\n\n```python\nimport pandas as pd\n\ndf = pd.read_csv(\"tests/test_case.csv\")\n```\n\nAlso, for every example, the `custom_defaults` used to sanitize the labels specific to the dataset is:\n\n```python\ncustom_defaults = {\n \"P\": \"promoters\",\n \"E\": \"enhancers\",\n \"A\": \"active \",\n \"I\": \"inactive \",\n \"+\": \" and \",\n \"\": \"anything\",\n \"Validation\": \"val\"\n}\n```\n\n### Horizontal Example A\n\nIn 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.\n\n```python\nfrom barplots import barplots\nimport pandas as pd\n\ndf = pd.read_csv(\"tests/test_case.csv\")\ncustom_defaults = {\n \"P\": \"promoters\",\n \"E\": \"enhancers\",\n \"A\": \"active \",\n \"I\": \"inactive \",\n \"+\": \" and \",\n \"\": \"anything\",\n \"Validation\": \"val\"\n}\n\nbarplots(\n df,\n groupby=[\"task\", \"model\"],\n orientation=\"horizontal\",\n show_legend=True,\n minor_rotation=90,\n custom_defaults=custom_defaults\n)\n```\n\nResult can be seen [here](https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/horizontal_legend_minor_rotation_val_auroc.png?raw=true).\n\n### Horizontal Example B\n\nIn this 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.\n\n```python\nfrom barplots import barplots\nimport pandas as pd\n\ndf = pd.read_csv(\"tests/test_case.csv\")\ncustom_defaults = {\n \"P\": \"promoters\",\n \"E\": \"enhancers\",\n \"A\": \"active \",\n \"I\": \"inactive \",\n \"+\": \" and \",\n \"\": \"anything\",\n \"Validation\": \"val\"\n}\n\nbarplots(\n df,\n groupby=[\"cell_line\", \"task\", \"model\"],\n orientation=\"horizontal\",\n show_legend=True,\n subplots=True,\n minor_rotation=90,\n custom_defaults=custom_defaults\n)\n```\n\n![Horizontal Example B](https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/horizontal_legend_subplots_minor_rotation_val_auroc.png?raw=true)\n\n### Horizontal Example C\n\nIn this example, we will plot horizontal bars, rotating the top group labels by 90 degrees, and displaying the bar labels as minor ticks.\n\n```python\nfrom barplots import barplots\nimport pandas as pd\n\ndf = pd.read_csv(\"tests/test_case.csv\")\ncustom_defaults = {\n \"P\": \"promoters\",\n \"E\": \"enhancers\",\n \"A\": \"active \",\n \"I\": \"inactive \",\n \"+\": \" and \",\n \"\": \"anything\",\n \"Validation\": \"val\"\n}\n\nbarplots(\n df,\n groupby=[\"task\", \"model\"],\n orientation=\"horizontal\",\n show_legend=False,\n major_rotation=90,\n custom_defaults=custom_defaults\n)\n```\n\nResult can be seen [here](https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/horizontal_major_rotation_val_auroc.png?raw=true).\n\n### Horizontal Example D\n\nIn this 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.\n\n```python\nfrom barplots import barplots\nimport pandas as pd\n\ndf = pd.read_csv(\"tests/test_case.csv\")\ncustom_defaults = {\n \"P\": \"promoters\",\n \"E\": \"enhancers\",\n \"A\": \"active \",\n \"I\": \"inactive \",\n \"+\": \" and \",\n \"\": \"anything\",\n \"Validation\": \"val\"\n}\n\nbarplots(\n df,\n groupby=[\"cell_line\", \"task\", \"model\"],\n orientation=\"horizontal\",\n show_legend=False,\n major_rotation=90,\n subplots=True,\n custom_defaults=custom_defaults\n)\n```\n\n![Horizontal Example D](https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/horizontal_subplots_major_rotation_val_auroc.png?raw=true)\n\n### Vertical Example A\n\nIn this example, we will plot the bars vertically and display the bar labels as a shared legend.\n\n```python\nfrom barplots import barplots\nimport pandas as pd\n\ndf = pd.read_csv(\"tests/test_case.csv\")\ncustom_defaults = {\n \"P\": \"promoters\",\n \"E\": \"enhancers\",\n \"A\": \"active \",\n \"I\": \"inactive \",\n \"+\": \" and \",\n \"\": \"anything\",\n \"Validation\": \"val\"\n}\n\nbarplots(\n df,\n groupby=[\"task\", \"model\"],\n orientation=\"vertical\",\n show_legend=True,\n custom_defaults=custom_defaults\n)\n```\n\nResult can be seen [here](https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/vertical_legend_val_auroc.png).\n\n### Vertical Example B\n\nIn this example, we will plot the top index as multiple subplots with vertical bars, displaying the bar labels as a shared legend.\n\n```python\nfrom barplots import barplots\nimport pandas as pd\n\ndf = pd.read_csv(\"tests/test_case.csv\")\ncustom_defaults = {\n \"P\": \"promoters\",\n \"E\": \"enhancers\",\n \"A\": \"active \",\n \"I\": \"inactive \",\n \"+\": \" and \",\n \"\": \"anything\",\n \"Validation\": \"val\"\n}\n\nbarplots(\n df,\n groupby=[\"cell_line\", \"task\", \"model\"],\n orientation=\"vertical\",\n show_legend=True,\n subplots=True,\n custom_defaults=custom_defaults\n)\n```\n\n![Vertical Example B](https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/vertical_legend_subplots_val_auroc.png)\n\n### Vertical Example C\n\nIn this example, we will plot vertical bars, rotating the minor group labels by 90 degrees, and displaying the bar labels as minor ticks.\n\n```python\nfrom barplots import barplots\nimport pandas as pd\n\ndf = pd.read_csv(\"tests/test_case.csv\")\ncustom_defaults = {\n \"P\": \"promoters\",\n \"E\": \"enhancers\",\n \"A\": \"active \",\n \"I\": \"inactive \",\n \"+\": \" and \",\n \"\": \"anything\",\n \"Validation\": \"val\"\n}\n\nbarplots(\n df,\n groupby=[\"task\", \"model\"],\n orientation=\"vertical\",\n show_legend=False,\n minor_rotation=90,\n custom_defaults=custom_defaults\n)\n```\n\nResult can be seen [here](https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/vertical_minor_rotation_val_auroc.png).\n\n### Vertical Example D\n\nIn this 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.\n\n```python\nfrom barplots import barplots\nimport pandas as pd\n\ndf = pd.read_csv(\"tests/test_case.csv\")\ncustom_defaults = {\n \"P\": \"promoters\",\n \"E\": \"enhancers\",\n \"A\": \"active \",\n \"I\": \"inactive \",\n \"+\": \" and \",\n \"\": \"anything\",\n \"Validation\": \"val\"\n}\n\nbarplots(\n df,\n groupby=[\"cell_line\", \"task\", \"model\"],\n orientation=\"vertical\",\n show_legend=False,\n minor_rotation=90,\n subplots=True,\n custom_defaults=custom_defaults\n)\n```\n\n![Vertical Example D](https://github.com/LucaCappelletti94/barplots/blob/master/examples/1/vertical_subplots_minor_rotation_val_auroc.png)\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python package to easily make barplots from multi-indexed dataframes.",
"version": "1.2.1",
"project_urls": {
"Homepage": "https://github.com/LucaCappelletti94/barplots"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9afd563e5aca5b8ee15619e50e15de133fec0c9fcfbc72ea8add7bef5d97c2fb",
"md5": "64926ab65c026d00ea8002b620648137",
"sha256": "0433b53832d196e403440fb626a7c21908b42dc6b5d360020cc09cf64e1a71bc"
},
"downloads": -1,
"filename": "barplots-1.2.1.tar.gz",
"has_sig": false,
"md5_digest": "64926ab65c026d00ea8002b620648137",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 21879,
"upload_time": "2024-10-28T15:34:30",
"upload_time_iso_8601": "2024-10-28T15:34:30.163136Z",
"url": "https://files.pythonhosted.org/packages/9a/fd/563e5aca5b8ee15619e50e15de133fec0c9fcfbc72ea8add7bef5d97c2fb/barplots-1.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-28 15:34:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "LucaCappelletti94",
"github_project": "barplots",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "barplots"
}