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
First Party data integration solution built for marketing teams to enable audience and conversion onboarding into Google Marketing products (Google Ads, Campaign Manager, Google Analytics).

Megalista Sample integration code for onboarding offline/CRM data from BigQuery as custom audiences or offline conversions in Google Ads, Google Analy

Google 76 Dec 29, 2022
Get charts, top artists and top songs WITHOUT LastFM API

LastFM Get charts, top artists and top songs WITHOUT LastFM API Usage Get stats (charts) We provide many filters and options to customize. Geo filter

null 4 Feb 11, 2022
An almost dependency-less, synchronous Discord gateway library meant for my personal use

An almost dependency-less, synchronous Discord gateway library meant for my personal use.

h0nda 4 Feb 5, 2022
A fork of discord.py meant to replace it

Texus A modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python. Key Features Modern Pythonic API using async and

Texus 1 Nov 18, 2021
This project is based on discord.py and is meant to be a 'Quick Start Bot' to cut down on the time it takes to write complex discord bots.

This project is based on discord.py and is meant to be a 'Quick Start Bot' to cut down on the time it takes to write complex discord bots.

Alec Ibarra 1 Mar 3, 2022
Easy Google Translate: Unofficial Google Translate API

easygoogletranslate Unofficial Google Translate API. This library does not need an api key or something else to use, it's free and simple. You can eit

Ahmet Eren Odacı 9 Nov 6, 2022
Tickergram is a Telegram bot to look up quotes, charts, general market sentiment and more.

Tickergram is a Telegram bot to look up quotes, charts, general market sentiment and more.

Alberto Ortega 25 Nov 26, 2022
A ShareX alternative for Mac OS built in Python.

Clipboard Uploader A ShareX alternative for Mac OS built in Python. Install and setup Download the latest release and put it in your applications fold

Ben Tettmar 2 Jun 7, 2022
a Disqus alternative

Isso – a commenting server similar to Disqus Isso – Ich schrei sonst – is a lightweight commenting server written in Python and JavaScript. It aims to

Martin Zimmermann 4.7k Jan 2, 2023
Faster Twitch Alerts is a highly customizable, lightning-fast alternative to Twitch's slow mobile notification system

Faster Twitch Alerts What is "Faster Twitch Alerts"? Faster Twitch Alerts is a highly customizable, lightning-fast alternative to Twitch's slow mobile

null 6 Dec 22, 2022
An alternative to OpenFaaS nats-queue-worker for long-running functions

OpenFaas Job Worker OpenFaas Job Worker is a fork of project : OSCAR Worker - https://github.com/grycap/oscar-worker Thanks to Sebástian Risco @srisco

Sebastien Aucouturier 1 Jan 7, 2022
Google scholar share - Simple python script to pull Google Scholar data from an author's profile

google_scholar_share Simple python script to pull Google Scholar data from an au

Paul Goldsmith-Pinkham 9 Sep 15, 2022
google-resumable-media Apache-2google-resumable-media (🥉28 · ⭐ 27) - Utilities for Google Media Downloads and Resumable.. Apache-2

google-resumable-media Utilities for Google Media Downloads and Resumable Uploads See the docs for examples and usage. Experimental asyncio Support Wh

Google APIs 36 Nov 22, 2022
An attendance bot that joins google meet automatically according to schedule and marks present in the google meet.

Google-meet-self-attendance-bot An attendance bot which joins google meet automatically according to schedule and marks present in the google meet. I

Sarvesh Wadi 12 Sep 20, 2022
Google Drive, OneDrive and Youtube as covert-channels - Control systems remotely by uploading files to Google Drive, OneDrive, Youtube or Telegram

covert-control Control systems remotely by uploading files to Google Drive, OneDrive, Youtube or Telegram using Python to create the files and the lis

Ricardo Ruiz 52 Dec 6, 2022
Automation that uses Github Actions, Google Drive API, YouTube Data API and youtube-dl together to feed BackJam app with new music

Automation that uses Github Actions, Google Drive API, YouTube Data API and youtube-dl together to feed BackJam app with new music

Antônio Oliveira 1 Nov 21, 2021
DB-Drive-CSV - This is app is can be used to access CSV file as JSON from Google Drive.

DB Drive CSV This is app is can be used to access CSV file as JSON from Google Drive. How To Use Create file/ upload file to Google Drive There's 2 fi

Hartawan Bahari M. 5 Oct 20, 2022
Google Sheets Python API

Google Spreadsheets Python API v4 Simple interface for working with Google Sheets. Features: Open a spreadsheet by title, key or url. Read, write, and

Anton Burnashev 6.2k Dec 30, 2022
🔍 Google Search unofficial API for Python with no external dependencies

Python Google Search API Unofficial Google Search API for Python. It uses web scraping in the background and is compatible with both Python 2 and 3. W

Avi Aryan 204 Dec 28, 2022