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
Group Management Bot

❤️ 𝗦𝗛𝗔𝗗𝗜𝗬𝗢 ❤️ A Powerful, Smart And Advance Group Manager ... Written with AioGram , Pyrogram and Telethon... ⭐️ Thanks to everyone who starred

Abdisamad Omar Mohamed 4 Dec 01, 2021
A GETTR API client written in Python.

GUTTR A GETTR client library written in Python. I rushed to get this out so it's a bit janky. Open an issue if something is broken or missing. Getting

Roger Johnston 13 Nov 23, 2022
The open source version of Tentro - A multipurpose Discord bot.

Welcome to Tentro 👋 A multipurpose Discord bot. 🏠 Homepage Install pip install -r requirements.txt Usage py Tentro.py Contributors 👤 Tentro Dev Tea

6 Jul 14, 2022
This project is a basic login system in terminal for Discord

Welcome to Discord Login System(Terminal) 👋 This project is a basic login system in terminal for Discord Author 👤 arukovic Github: @SONIC-CODEZ Show

SONIC-CODEZ 2 Feb 11, 2022
An api, written in Python, for Investopedia's paper trading stock simulator.

investopedia-trading-api An API, written in Python, for Investopedia's paper trading stock simulator. Pull requests welcome. This library is now Pytho

Kirk Thaker 178 Jan 06, 2023
A Python Client for News API

newsapi-python A Python client for the News API. License Provided under MIT License by Matt Lisivick. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRAN

Matt Lisivick 281 Dec 29, 2022
Discord raiding tool. Made in python 3.9

XSpammer Discord raiding tool with 20 features. YT Showcase Requirements/Installation Python 3.7+ [https://python.org] Run setup.bat to install the es

Tiie 6 Oct 24, 2022
Another secured and Yet Fastest telegram userbot

Vision-UserBot A stable, simple Telegram UserBot in Pyrogram! Support Variables ➨ TG_APP_ID - Your Telegram Api id. ➨ TG_API_HASH - Your Telegram Api

TeamVision 40 Oct 24, 2022
Estudo de como criar uma api para o gerenciamento de livros usando a django restframework

Boa parte do projeto foi beaseado nesse vídeo e nesse artigo. Se assim como eu, você entrou agora no mundo BackEnd, recomendo fortemente tais materiai

Michel Ledig 14 Jun 28, 2022
An interactive App to play with Spotify data, both from the Spotify Web API and from CSV datasets.

An interactive App to play with Spotify data, both from the Spotify Web API and from CSV datasets.

Caio Lang 3 Jan 24, 2022
❄️ Don't waste your money paying for new tokens, once you have used your tokens, clean them up and resell them!

TokenCleaner Don't waste your money paying for new tokens, once you have used your tokens, clean them up and resell them! If you have a very large qua

0xVichy 59 Nov 14, 2022
A discord bot for checking what linked profiles a user has to their Ubisoft account

ubisoft_discord_profiles A Discord bot for checking what linked profiles a user has to their Ubisoft account. This can be setup using an enviromental

Andrei 1 Dec 17, 2021
A melhor maneira de atender seus clientes no Telegram!

Clientes.Chat Sobre o serviço Configuração Banco de Dados Variáveis de Ambiente Docker Python Heroku Contribuição Sobre o serviço A maneira mais organ

Gabriel R F 10 Oct 12, 2022
Connect your Nintendo Switch playing status to Discord!

Disclaimer: Unfortunately, it appears that Nintendo has removed returning self-Presence in their API as of recently, making this project near obsolete

Deltaion Lee 145 Dec 30, 2022
A Telegram Bin Checker Bot made with python for check Bin valid or Invalid. 💳

Bin Checker Bot A Telegram Bin Checker Bot made with python for check Bin valid or Invalid. 📌 Deploy On Heroku 🏷 Environment Variables API_ID - Your

Chamindu Denuwan 20 Dec 10, 2022
Python interface to the World Bank Indicators and Climate APIs

wbpy A Python interface to the World Bank Indicators and Climate APIs. Readthedocs Github source World Bank API docs The Indicators API lets you acces

Matt Duck 47 Oct 31, 2022
A bot can play all variants, but standard are abit weak, so if you need strongest you can change fsf instead of stockfish_14_Dev

MAINTAINERS Drdisrespect1 and drrespectable lichess-bot Engine communication code taken from https://github.com/ShailChoksi/lichess-bot by ShailChoksi

RPNS Nimsilu 1 Dec 12, 2021
An Advanced Python Playing Card Module that makes creating playing card games simple and easy!

playingcards.py An Advanced Python Playing Card Module that makes creating playing card games simple and easy! Features Easy to Understand Class Objec

Blake Potvin 5 Aug 30, 2022
Telegram bot to stream videos in telegram Voice Chat for both groups and channels

Telegram bot to stream videos in telegram Voice Chat for both groups and channels. Supports live steams, YouTube videos and telegram media. Supports scheduling streams, recording and many more.

Akki ThePro 2 Sep 11, 2022
LyricsGenius: a Python client for the Genius.com API

LyricsGenius: a Python client for the Genius.com API lyricsgenius provides a simple interface to the song, artist, and lyrics data stored on Genius.co

KevinChunye 2 Jun 30, 2022