Skip to main content

Easily create graphs using custom styling

Project description

Cmotions Dataviz

cmo_dataviz is a Python library created by The Analytics Lab, which is powered by Cmotions. This library makes it easy for us to create graphs in our prefered styling and using Cmotions colors by default. Nothing fancy, but very useful for our consultants. Mostly since this package is used in other packages, which makes our workflow simpler and more efficient.

Since we love to share what we do, why not also do that with our packages, that is why we've decided to make (almost) all of our packages open source, this way we hope to give back to the community that brings us so much. Enjoy!

Installation

Install cmo_dataviz using pip

pip install cmo-dataviz

If you want to be able to use the tutorial notebook or the code below, you also need to install pydataset using pip

pip install pydataset

Usage

from pydataset import data
import cmo_dataviz as dv
import matplotlib.pyplot as plt
import pandas as pd

# import your own stylesheet if relevant
dv.import_style('mydocuments/mystylesheet.mplstyle')

df = data("iris")
df_summary = df.groupby('Species').agg({'Sepal.Length': 'mean','Sepal.Width': 'sum', 'Petal.Length': 'mean', 'Petal.Width': 'sum'}).reset_index()

# create a single plot with default settings for size and so on
dv.create_horizontal_barplot(data=df_summary, x_var='Sepal.Width', y_var='Species', x_label="", title="", ax=None)
plt.show()

# adjust the size (or other settings) of the plot
fig, ax = plt.subplots(figsize=(5,5))
dv.create_horizontal_barplot(data=df_summary, x_var='Sepal.Width', y_var='Species', x_label="", title="", ax=ax)
plt.show()

# combine multiple graphs in a single plot
fig, ax = plt.subplots(2, 2, figsize=(10,7))
dv.create_histogram(data=df, var="Petal.Width", color_by="Species", bins=10, max_categories=50, ax=ax[0,0], title="our histogram")
dv.create_scatterplot(data=df, x_var="Sepal.Width", y_var="Sepal.Length", title="our scatterplot", ax=ax[0,1])
dv.create_boxplot(data=df, x_var="Petal.Length", y_var="Species", color_by=None, ax=ax[1,0], title="our boxplot")
dv.create_swarmplot(data=df, x_var="Sepal.Width", y_var=None, color_by= "Species", ax=ax[1,1])
plt.show()

# create example data for a network graph
networkdata = {
    'source': ['A', 'B', 'C', 'D', 'E', 'B', 'C', 'C', 'C'],
    'target': ['B', 'C', 'D', 'E', 'A', 'D', 'E', 'D', 'D'],
    'label': ['relation1', 'relation2', 'relation3', 'relation4', 'relation5', 'relation6', 'relation7', 'relation8', 'relation9']
}
networkdata = pd.DataFrame(networkdata)

# create a network graph
dv.create_network_graph(
    data=networkdata,
    node_1='source',
    node_2='target',
    edge_label='label',
    title="my network graph",
    figsize=(5, 5),
    ax=None,
    seed=1502)
plt.show()

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.

License

GNU General Public License v3.0

Contributors

Jeanine Schoonemann
Contact us

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

cmo_dataviz-0.1.2.tar.gz (108.4 kB view hashes)

Uploaded Source

Built Distribution

cmo_dataviz-0.1.2-py3-none-any.whl (105.3 kB view hashes)

Uploaded Python 3

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