A Google Charts API for Python, meant to be used as an alternative to matplotlib.

Overview

GooPyCharts

A Google Charts API for Python 2 and 3, meant to be used as an alternative to matplotlib. Syntax is similar to MATLAB. The goal of this project is to make an easy to use graphing utility for the most common graphical use cases.

Python (Web Browser) Screenshot

Alt text

Jupyter Screenshot

Alt text

You can find a Jupyter notebook with examples here. A Python script with examples can be found here.

Installation and use

GooPyCharts can be installed with pip using the following command:

pip install gpcharts

Alternately, you can put gpcharts.py in your working directory or library path. Then, import gpcharts to your Python code:

from gpcharts import figure

That's it. To get started, you can plot and display a simple graph with the following code:

fig1 = figure()
fig1.plot([8,7,6,5,4])

This will open the chart in a Jupyter notebook if you're using one. If you aren't, it will open a webpage in your default browser with the plot.

For more examples, see testGraph.py. Examples include scatter plots, adding titles/plot labels, and datetime graphs. For simple bar and histogram examples, see testGraph_barAndHist.py. For a jupyter notebook example, see gpcharts test.ipynb. The example does not display properly in Github, but the file should work if you download it and then do "Cell->Run All."

For timeseries, use as your x-axis the following format (as a string): 'yyyy-mm-dd HH:MM:SS'. The 'HH:MM:SS' is optional, but be consistent throughout your input. GooPyCharts will take care of the rest.

Each kind of chart has a number of possible configuration options provided by the Google Chart API and GooPyCharts allows you to use any combination of them via keywork arguments. For example, to show a line chart without a legend and with straight lines between each of the po, you can write:

f1 = figure()
f1.plot([1,2], legend="'none'", curveType="'straight'")

You can determine the name of the keyword arguments by consulting the Google Charts API documentation for each chart, such as the Line Chart. You'll notice that the example strings above are surrounded by single quotes. You are injecting a literal JavaScript option into the chart, so the final drawChart method will have single quotes around the option. This can be somewhat inconvenient, but it is necessary because certain options require dictionaries.

You can use these customization features to overwrite the default options within GooPyCharts. The default GooPyCharts curveType is 'function', which produces curved lines, but the example above replaces that with the Google Charts API default, which is not curved.

Features

  • line, scatter, bar, column, and histogram plots
  • plot multiple columns in one call
  • tooltips
  • easy access to best fit line for scatter plots
  • full access to the charts' configuration options
  • save figure as HTML or PNG
  • save data to CSV
  • zooming (click and drag to zoom, right-click to reset zoom)
  • log scale for y-axis
  • automatic datetime/string/numeric detection on x-axis input (a huge pain point in both MATLAB and matplotlib)
  • Easy webpage integration (just copy and paste the HTML/Javascript from the output HTML file)
    • To get the HTML in code, cast a figure object to str. The figure.get_drawChart method returns just the JavaScript function that draws the chart.
  • Jupyter notebook integration

Some Rules

  • Headers are column titles. The dependent variable header will be the title of the x axis, and the other headers will appear in the legend.
  • If you have headers on your dependent variables, make sure to also have a header on the independent variable.
  • The header on the x axis will overwrite the x label. The y label is independent and is not assigned any header.
  • If you want to do some fancy math using NumPy and then plot a NumPy array, use the tolist() function to convert the array to a Python list.

Comparisons to Matplotlib and MATLAB

See the README's compareToMatplotlib.md and compareToMATLAB.md.

Please report bugs to me and I'll do my best to fix them in short order.

Comments
  • Updates allowing retrieval of JS code, column chart

    Updates allowing retrieval of JS code, column chart

    So, first, apologies for this being so big. I needed a column chart and the ability to get the JS code and each change followed from there.

    All of the changes are essentially backwards compatible. The biggest change is that the chart methods no longer automatically open the Jupyter notebook or web browser on every call. dispFile() (or its new alias, show) needs to be called explicitly unless the nb parameter of the chart method is True.

    This change allows stuff like the following:

    >>> fig1 = figure()
    >>> fig1.plot([1,2,3,4])
    >>> str(fig1)
    [The page source]
    >>> fig1.get_drawChart()
    [The JS code of just the drawChart method]
    >>> fig1.show()
    [write the file, open the notebook/web browser]
    >>> fig1.write()
    [just write the file]
    >>> fig1.nb()
    [open in notebook]
    >>> fig1.wb()
    [open in browser]
    

    So, the obvious way this is not 100% backwards compatible is that anything relying on the chart to appear directly after plot is called now needs to be followed by show. All code using the methods like plot_nb works with no change because I retained the chart method parameter nb, as explained above.

    Another change is that dispFile now automatically detects if you are in a notebook. If you are, it displays in the notebook by calling nb(). If you are not, it opens in a web browser. The boolean parameter nb on this method now does nothing, and raises a DeprecationWarning if you're running the code with python -W on.

    Also, I moved the templates out of the gpcharts.py file because they were in the way. Because this package in intended to be installed via PIP, there's no specific benefit to keeping those in the main file.

    opened by lethargilistic 3
  • PIP version breaks

    PIP version breaks

    opened by lethargilistic 2
  • fix the broken link of image file in the README.md

    fix the broken link of image file in the README.md

    I tried to use the backslash \ to fix the broken image link, but for some reason that wasn't working as well. So then I looked at how other files in the "assets" directory are named. And followed the same convention. And now the README.md is fixed.

    Before

    screenshot from 2017-09-03 21-55-46

    After

    screenshot from 2017-09-03 22-03-56

    opened by anshulxyz 1
  • Allow access to arbitrary options from Google Charts API

    Allow access to arbitrary options from Google Charts API

    The new feature

    This uses **kwargs to allow a user to specify arbitrary options to the plot methods, opening up all the customization potential of the Google Charts API. Here's some example usage.

    Neither of these figures will have legends:

    from gpcharts import figure
    
    f1 = figure()
    f1.plot([1,2], legend="'none'")
    
    f2 = figure()
    op = {'legend':"'none'"}
    f2.scatter([1,2,3],**op)
    
    

    An interesting consequence

    fig.plot(xdata=data, curveType="'asdfasdf'")
    

    If there is more than one instance of a key within the JavaScript options dictionary, the last assignment of the key is used. That means these options can override GooPyCharts default settings. Users can do whatever they want!

    As you know, GooPyCharts defaults to curveType = 'function'. Any invalid string (like this example's asdfasdf) makes Google Chart API use its default behavior: straight lines. You could, of course, also write 'straight lines', but, for this demonstration's purposes, that would obfuscate what's really going on.

    opened by lethargilistic 0
  • Fixing Python4 compatibility issue

    Fixing Python4 compatibility issue

    It is presumed that Python4 will be mostly, if not completely, backwards compatible with Python3. At the same time, it will not revert to Python2 compatibility. As such, Python3 patches like this should also be written to be seen by future versions of Python, so they're less likely to break with that eventual update.

    opened by lethargilistic 0
  • Trendline conflict possible

    Trendline conflict possible

    I realized this after reviewing the code the other day, but a line like this is possible:

    fig5.scatter([1,2,3,4,5],[[1,5],[2,4],[3,3],[4,2],[5,1]],
                 trendline=True, trendlines="{}")
    

    This is a chart where we indicate that we use the trendline option, but also provide an empty trendlines option as an "other" option. No trendline appears.

    Under the hood, the trendline option is added before other options, so the other options take precedence and the conflict is possible.

    So the question is: do we care? It seems like a really niche thing that could only be unintentional, but it is still possible.

    opened by lethargilistic 0
Releases(v1.3.3)
Owner
Sagnik Ghosh
Sagnik Ghosh
An open-source, multipurpose, configurable discord bot that does it all

Spacebot is an open source discord bot that is designed to be fun, easy to use, and replace every other discord bot out there!! Feel free to add a star ⭐ to the repository to promote the project!

Dhravya Shah 41 Dec 10, 2022
Automate HoYoLAB Genshin Daily Check-In Using Github Actions

Genshin Daily Check-In 🤖 Automate HoYoLAB Daily Check-In Using Github Actions KOR, ENG Instructions Fork the repository Go to Settings - Secrets Cli

Leo Kim 41 Jun 24, 2022
A (probably) working Kik name checker

KikNameChecker !THIS ONLY CHECKS WS2.KIK.COM ENDPOINT! \ Will add user inputted endpoints thing \ A (probably) working Kik name checker Started as a s

insert edgy and cool name 1 Dec 17, 2022
A python script for hitting the kik API to enumerate people based on a username/userlist

kick3d Recon script for enumerating users off of the Kik API. This script has the ability to check single usernames or run through a userlist of usern

Sakura Samurai 19 Oct 04, 2021
Simple integrate of API musixmatch.com with python

Python Musixmatch Simple integrate of API musixmatch.com with python Quick start $ pip install pymusixmatch or $ python setup.py install Authenticatio

Hudson Brendon 79 Dec 20, 2022
A tool for exporting Telegram group chats into static websites, preserving chat history like mailing list archives.

tg-archive is a tool for exporting Telegram group chats into static websites, preserving chat history like mailing list archives. Preview The @fossuni

Kailash Nadh 400 Dec 27, 2022
Role Based Access Control for Slack-Bolt Applications

Role Based Access Control for Slack-Bolt Apps Role Based Access Control (RBAC) is a term applied to limiting the authorization for a specific operatio

Jeremy Schulman 7 Jan 06, 2022
A python library for anti-captcha.com

AntiCaptcha A python library for anti-captcha.com Documentation for the API Requirements git Install git clone https://github.com/ShayBox/AntiCaptcha.

Shayne Hartford 3 Dec 16, 2022
A bot can be used to broadcast your messages ( Text & Media ) to the Subscribers

Broadcast Bot A Telegram bot to send messages and medias to the subscribers directly through bot. Authorized users of the bot can send messages (Texts

Shabin-k 8 Oct 21, 2022
A powerfull SMS Bomber for Bangladesh . NO limite .Unlimited SMS Spaming

RedBomberBD A powerfull SMS Bomber for Bangladesh . NO limite .Unlimited SMS Spaming Installation Install my-tool on termux by using thoes commands pk

Abdullah Al Redwan 3 Feb 16, 2022
A simple language translator with python and google translate api

Language translator with python A simple language translator with python and google translate api Install pip and python 3.9. All the required depende

0 Nov 11, 2021
Telegram bot to scrape images from the reddit universe

Telegram bot to scrape images from the reddit universe

XD22 3 Sep 30, 2022
StringSessionGenerator - A Telegram bot to generate pyrogram and telethon string session

⭐️ String Session Generator ⭐️ Genrate String Session Using this bot. Made by TeamUltronX 🔥 String Session Demo Bot: Environment Variables Mandatory

TheUltronX 1 Dec 31, 2021
Handles SDVX EXCEED GEAR result screen photos and attempts to read it.

Handles SDVX EXCEED GEAR result screen photos and attempts to read it.

silverhawke 1 Jan 08, 2022
Telegram bot that sends new offers from otomoto.pl

Telegram bot that sends new offers under certain filters from otomoto.pl How to use this bot? Install requirements with pip install -r requirements.tx

Mikhail Zanka 1 Feb 14, 2022
A free sniper bot built to work with PancakeSwap: Router V2

Pancakeswap Sniper Bot PancakeSwap sniper bot. Automated sniping bot to snipe crypto coin launches. How it works The sniping bot can be used in three

89 Aug 06, 2022
A.I and game for gomoku, working only on windows

Gomoku (A.I of gomoku) The goal of the project is to create an artificial intelligence of gomoku. Goals Beat the opponent. Requirements Python 3.7+ Wo

Luis Rosario 13 Jun 20, 2021
Documentation and Samples for the Official HN API

Hacker News API Overview In partnership with Firebase, we're making the public Hacker News data available in near real time. Firebase enables easy acc

Y Combinator Hacker News 9.6k Jan 03, 2023
A complete Python application to automatize the process of uploading files to Amazon S3

Upload files or folders (even with subfolders) to Amazon S3 in a totally automatized way taking advantage of: Amazon S3 Multipart Upload: The uploaded

Pol Alzina 1 Nov 20, 2021
A python package for AxisVM

PyAxisVM The package is under development. Follow us on social media, where we'll announce the first release! Overview The PyAxisVM project offers a h

AxisVM - InterCAD 8 Nov 19, 2022