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
A telegram bot writen in python for mirroring files on the internet to our beloved Google Drive

[] Mirror Bot This is a telegram bot writen in python for mirroring files on the internet to our beloved Google Drive. Deploying on Heroku Give Star &

43 Mar 06, 2022
Some examples regarding how to use the Twitter APIs for academic research

Twitter Developer Platform: Using Twitter APIs for Academic Research All the scripts require a config.ini file in which the keys are put. There is a t

Federico Bianchi 6 Feb 13, 2022
Simple Telegram Bot to Download and Upload Files From Mega.nz

Mega.nz-Bot Simple Telegram Bot to Download Files From Mega.nz and Upload It to Telegram Features All Mega.nz File Links supported No login required A

I'm Not A Bot #Left_TG 245 Jan 01, 2023
ChannelActionsBot - Channel Actions Bot With Python

ChannelActionsBot Can be found on telegram as @ChannelActionsBot! Features Auto

Aditya 56 Dec 30, 2022
A python tool to Automate Whatsapp through Whatsapp web

This python tool is used to Automate Whatsapp through Whatsapp web. We can add number of contacts whom we want to send text messages on perticular time

5 Jul 21, 2022
Demonstrate how GitHub OIDC token getting should be included in boto3

boto3 should add direct support for AssumeRoleWithWebIdentity for GitHub Actions There is a aws-actions/configure-aws-credentials action that will get

Ben Kehoe 11 Aug 29, 2022
Discord Remote Administration Tool fully written in Python3.

DiscordRAT Discord Remote Administration Tool fully written in Python3. This is a RAT controlled over Discord with over 50 post exploitation modules.

hozzywozzy 2 Feb 06, 2022
D(HE)ater is a security tool can perform DoS attack by enforcing the DHE key exchange.

D(HE)ater D(HE)ater is an attacking tool based on CPU heating in that it forces the ephemeral variant of Diffie-Hellman key exchange (DHE) in given cr

Balasys 138 Dec 15, 2022
✖️ Unofficial API of 1337x.to

✖️ Unofficial Python API Wrapper of 1337x This is the unofficial API of 1337x. It supports all proxies of 1337x and almost all functions of 1337x. You

Hemanta Pokharel 71 Dec 26, 2022
Asynchronous Guilded API wrapper for Python

Welcome to guilded.py, a discord.py-esque asynchronous Python wrapper for the Guilded API. If you know discord.py, you know guilded.py. Documentation

shay 115 Dec 30, 2022
Osmopy - osmo python client library

osmopy Version 0.0.2 Tools for Osmosis wallet management and offline transaction

5 May 22, 2022
Utility for downloading fanfiction in bulk from the Archive of Our Own

What is this? This is a program intended to help you download fanfiction from the Archive of Our Own in bulk. This program is primarily intended to wo

73 Dec 30, 2022
Michelle is a Discord Bot coded in Python with Discord.py by Mudit07.

Michelle is a Discord Bot coded in Python with Discord.py by Mudit07.

Michelle 3 Oct 09, 2021
An integrated information collection tool

infoscaner 环境配置 目前infoscaner仅支持在linux上运行,建议运行在最新版本的kali中 infoscaner是基于python3版本实现的,运行之前首先安装python库 如果同时存在python2和python3,请输入以下命令 pip3 install -r requi

CMACCKK 74 Sep 13, 2021
Export Statistics for a Telegram Group Chat

Telegram Statistics Export Statistics for a Telegram Group Chat How to Run First, in main repo directory, run the following code to add src to your PY

Ali Hejazizo 22 Dec 05, 2022
A file-based quote bot written in Python

Let's Write a Python Quote Bot! This repository will get you started with building a quote bot in Python. It's meant to be used along with the Learnin

1 Nov 01, 2021
An attempt to escape the horrible JIRA editor.

An attempt to escape the horrible JIRA editor. jira_filter.py is a pandoc filter that cleans up some of JIRA's html so that it can be converted to Mar

Stefan Matting 2 Feb 10, 2022
Simple Discord bot which logs several events in your server

logging-bot Simple Discord bot which logs several events in your server, including: Message Edits Message Deletes Role Adds Role Removes Member joins

1 Feb 14, 2022
SEMID - OSINT module with lots of discord functions

SEMID Framework About Semid is a framework with different Discord functions and

Hima 20 Sep 23, 2022
My homeserver setup. Everything managed securely using Portainer.

homeserver-traefik-portainer Features: access all services with free TLS from letsencrypt using your own domain running a side project is super simple

Tomasz Wójcik 44 Jan 03, 2023