๐Ÿ“Š Charts with pure python

Overview

chart

MIT Travis PyPI Downloads

A zero-dependency python package that prints basic charts to a Jupyter output

Charts supported:

  • Bar graphs
  • Scatter plots
  • Histograms
  • ๐Ÿ‘ ๐Ÿ“Š ๐Ÿ‘

Examples

Bar graphs can be drawn quickly with the bar function:

from chart import bar

x = [500, 200, 900, 400]
y = ['marc', 'mummify', 'chart', 'sausagelink']

bar(x, y)
       marc: โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡             
    mummify: โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡                       
      chart: โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡
sausagelink: โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡                              

And the bar function can accept columns from a pd.DataFrame:

from chart import bar
import pandas as pd

df = pd.DataFrame({
    'artist': ['Tame Impala', 'Childish Gambino', 'The Knocks'],
    'listens': [8_456_831, 18_185_245, 2_556_448]
})
bar(df.listens, df.artist, width=20, label_width=11, mark='๐Ÿ”Š')
Tame Impala: ๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š           
Childish Ga: ๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š
 The Knocks: ๐Ÿ”Š๐Ÿ”Š๐Ÿ”Š                                

Histograms are just as easy:

from chart import histogram

x = [1, 2, 4, 3, 3, 1, 7, 9, 9, 1, 3, 2, 1, 2]

histogram(x)
โ–‡        
โ–‡        
โ–‡        
โ–‡        
โ–‡ โ–‡      
โ–‡ โ–‡      
โ–‡ โ–‡      
โ–‡ โ–‡     โ–‡
โ–‡ โ–‡     โ–‡
โ–‡ โ–‡   โ–‡ โ–‡

And they can accept objects created by scipy:

from chart import histogram
import scipy.stats as stats
import numpy as np

np.random.seed(14)
n = stats.norm(loc=0, scale=10)

histogram(n.rvs(100), bins=14, height=7, mark='๐Ÿ‘')
            ๐Ÿ‘              
            ๐Ÿ‘   ๐Ÿ‘          
            ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘          
            ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘          
        ๐Ÿ‘   ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘          
      ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘    
      ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘   ๐Ÿ‘

Scatter plots can be drawn with a simple scatter call:

from chart import scatter

x = range(0, 20)
y = range(0, 20)

scatter(x, y)
                                       โ€ข
                                   โ€ข โ€ข  
                                 โ€ข      
                             โ€ข โ€ข        
                         โ€ข โ€ข            
                       โ€ข                
                  โ€ข  โ€ข                  
                โ€ข                       
            โ€ข โ€ข                         
        โ€ข โ€ข                             
      โ€ข                                 
  โ€ข โ€ข                                   
โ€ข                                       

And at this point you gotta know it works with any np.array:

from chart import scatter
import numpy as np

np.random.seed(1)
N = 100
x = np.random.normal(100, 50, size=N)
y = x * -2 + 25 + np.random.normal(0, 25, size=N)

scatter(x, y, width=20, height=9, mark='^')
^^                  
 ^                  
    ^^^             
    ^^^^^^^         
       ^^^^^^       
        ^^^^^^^     
            ^^^^    
             ^^^^^ ^
                ^^ ^

In fact, all chart functions work with pandas, numpy, scipy and regular python objects.

Preprocessors

In order to create the simple outputs generated by bar, histogram, and scatter I had to create a couple of preprocessors, namely: NumberBinarizer and RangeScaler.

I tried to adhere to the scikit-learn API in their construction. Although you won't need them to use chart here they are for your tinkering:

from chart.preprocessing import NumberBinarizer

nb = NumberBinarizer(bins=4)
x = range(10)
nb.fit(x)
nb.transform(x)
[0, 0, 0, 1, 1, 2, 2, 3, 3, 3]
from chart.preprocessing import RangeScaler

rs = RangeScaler(out_range=(0, 10), round=False)
x = range(50, 59)
rs.fit_transform(x)
[0.0, 1.25, 2.5, 3.75, 5.0, 6.25, 7.5, 8.75, 10.0]

Installation

pip install chart

Contribute

For feature requests or bug reports, please use Github Issues

Inspiration

I wanted a super-light-weight library that would allow me to quickly grok data. Matplotlib had too many dependencies, and Altair seemed overkill. Though I really like the idea of termgraph, it didn't really fit well or integrate with my Jupyter workflow. Here's to chart ๐Ÿฅ‚ (still can't believe I got it on PyPI)

You might also like...
๐Ÿž ๐Ÿ“Š Ladybug extension to generate 2D charts

ladybug-charts Ladybug extension to generate 2D charts. Installation pip install ladybug-charts QuickStart import ladybug_charts API Documentation Loc

GitHub English Top Charts

Help you discover excellent English projects and get rid of the interference of other spoken language.

Data-FX is an addon for Blender (2.9) that allows for the visualization of data with different charts
Data-FX is an addon for Blender (2.9) that allows for the visualization of data with different charts

Data-FX Data-FX is an addon for Blender (2.9) that allows for the visualization of data with different charts Currently, there are only 2 chart option

Tools for writing, submitting, debugging, and monitoring Storm topologies in pure Python

Petrel Tools for writing, submitting, debugging, and monitoring Storm topologies in pure Python. NOTE: The base Storm package provides storm.py, which

A gui application to visualize various sorting algorithms using pure python.
A gui application to visualize various sorting algorithms using pure python.

Sorting Algorithm Visualizer A gui application to visualize various sorting algorithms using pure python. Language : Python 3 Libraries required Tkint

Visual Python is a GUI-based Python code generator, developed on the Jupyter Notebook environment as an extension.
Visual Python is a GUI-based Python code generator, developed on the Jupyter Notebook environment as an extension.

Visual Python is a GUI-based Python code generator, developed on the Jupyter Notebook environment as an extension.

A Python Binder that merge 2 files with any extension by creating a new python file and compiling it to exe which runs both payloads.
A Python Binder that merge 2 files with any extension by creating a new python file and compiling it to exe which runs both payloads.

Update ! ANONFILE MIGHT NOT WORK ! About A Python Binder that merge 2 files with any extension by creating a new python file and compiling it to exe w

Declarative statistical visualization library for Python
Declarative statistical visualization library for Python

Altair http://altair-viz.github.io Altair is a declarative statistical visualization library for Python. With Altair, you can spend more time understa

Interactive Data Visualization in the browser, from  Python
Interactive Data Visualization in the browser, from Python

Bokeh is an interactive visualization library for modern web browsers. It provides elegant, concise construction of versatile graphics, and affords hi

Comments
  • [Feature Request] Multiple Marks

    [Feature Request] Multiple Marks

    Totally possible I'm an idiot here, but does this support multiple marks? I enjoy this package a lot but I can't seem to figure out how to get multiple marks to be used.

    Example snippet of how I'd expect this to work:

    `from chart import bar

    x = [3,100] y = ['useful things', 'useless things']

    bar(x,y,mark=['๐Ÿ‘','๐Ÿ”Š'])`

    opened by si-phi 0
Owner
Max Humber
Human
Max Humber
Python library that makes it easy for data scientists to create charts.

Chartify Chartify is a Python library that makes it easy for data scientists to create charts. Why use Chartify? Consistent input data format: Spend l

Spotify 3.2k Jan 4, 2023
๐Ÿง‡ Make Waffle Charts in Python.

PyWaffle PyWaffle is an open source, MIT-licensed Python package for plotting waffle charts. It provides a Figure constructor class Waffle, which coul

Guangyang Li 528 Jan 2, 2023
Python library that makes it easy for data scientists to create charts.

Chartify Chartify is a Python library that makes it easy for data scientists to create charts. Why use Chartify? Consistent input data format: Spend l

Spotify 2.8k Feb 18, 2021
๐Ÿง‡ Make Waffle Charts in Python.

PyWaffle PyWaffle is an open source, MIT-licensed Python package for plotting waffle charts. It provides a Figure constructor class Waffle, which coul

Guangyang Li 397 Feb 17, 2021
Python library that makes it easy for data scientists to create charts.

Chartify Chartify is a Python library that makes it easy for data scientists to create charts. Why use Chartify? Consistent input data format: Spend l

Spotify 3.2k Jan 1, 2023
Dragโ€™nโ€™drop Pivot Tables and Charts for Jupyter/IPython Notebook, care of PivotTable.js

pivottablejs: the Python module Dragโ€™nโ€™drop Pivot Tables and Charts for Jupyter/IPython Notebook, care of PivotTable.js Installation pip install pivot

Nicolas Kruchten 512 Dec 26, 2022
Dragโ€™nโ€™drop Pivot Tables and Charts for Jupyter/IPython Notebook, care of PivotTable.js

pivottablejs: the Python module Dragโ€™nโ€™drop Pivot Tables and Charts for Jupyter/IPython Notebook, care of PivotTable.js Installation pip install pivot

Nicolas Kruchten 419 Feb 11, 2021
Streamlit dashboard examples - Twitter cashtags, StockTwits, WSB, Charts, SQL Pattern Scanner

streamlit-dashboards Streamlit dashboard examples - Twitter cashtags, StockTwits, WSB, Charts, SQL Pattern Scanner Tutorial Video https://ww

null 122 Dec 21, 2022
mysql relation charts

sqlcharts ่‡ชๅŠจ็”Ÿๆˆๆ•ฐๆฎๅบ“ๅ…ณ่”ๅ…ณ็ณปๅ›พ ๅคๅˆถsettings.py.example ้‡ๅ‘ฝๅไธบsettings.py ๅฐ†ๆ•ฐๆฎๅบ“้…็ฝฎไฟกๆฏๅกซๅ…ฅsettings.DATABASE๏ผŒ็›ฎๅ‰ๆ”ฏๆŒmysqlๅ’Œpostgresql ๆ‰ง่กŒ python build.py -b๏ผŒ-bๆ˜ฏ่ฏปๅ–ๆ•ฐๆฎๅบ“่กจ็ป“ๆž„๏ผŒๅฆ‚ๆžœๅชๆ›ดๆ–ฐๅŒน

null 6 Aug 22, 2022
Altair extension for saving charts in a variety of formats.

Altair Saver This packge provides extensions to Altair for saving charts to a variety of output types. Supported output formats are: .json/.vl.json: V

Altair 85 Dec 9, 2022