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
This is an Advanced Calculator maybe with Discord Buttons in python.

Welcome! This is an Advanced Calculator maybe with Discord Buttons in python. This was the first version of the calculator, made for my discord bot, P

Polsulpicien 18 Dec 24, 2022
DadBot 2.0 is an interactive bot that reflects the personality of a typical dad

DadBot 2.0 is an interactive bot that reflects the personality of a typical dad! You can start by running main while all directories are maintained as they are on this GitHub.

1 Dec 04, 2021
Image-Bot-Discord - This Is a discord bot that shows the specific image you search from Google

Advanced Discord.py Image Bot CREDITS Made by RLX and Mathiscool README by Milrato Installation Guide in .env Adjust the TOKEN python main.py to start

RLX 3 Jan 16, 2022
This is a unofficial library for making bots in rubika.

rubika this is a unofficial library for making bots in rubika using this library you can make your own0 rubika bot and control that those bots that ma

Bahman 50 Jan 02, 2023
Python script for download course from platzi.com

Platzi Downloader Tool Esta es una pequeña herramienta que hace mucho y que te ahorra una gran cantidad de trabajo a la hora de descargar cursos de Pl

Devil64-Dev 21 Sep 22, 2022
Catinthebox - Awesome bot for Mastodon

Cat In The Box :3 Description Awesome bot for Mastodon Requirements python pip g

satanist 0 Jan 19, 2022
Github repository started notify 💕

Github repository started notify 💕

4 Aug 06, 2022
A Telegram Video Watermark Adder Bot

Watermark-Bot A Telegram Video Watermark Adder Bot by @VideosWaterMarkRobot Features: Save Custom Watermark Image. Auto Resize Watermark According to

5 Jun 17, 2022
Data portal client and server for NMDC.

NMDC Server and Client Portal Getting started with Docker install ldc install submodules via git submodule update --init --recursive In order to popul

National Microbiome Data Collaborative 7 Dec 14, 2022
This project uses Youtube data API's to do youtube tags analysis based on viewCount, comments etc.

Youtube video details analyser Steps to run this project Please set the AuthKey which you can fetch from google developer console and paste it in the

1 Nov 21, 2021
A modular Telegram Python bot running on python3 with a sqlalchemy, redislab, mongo database, telethon, and pyrogram.

Zeldris Robot A modular Telegram Python bot running on python3 with a sqlalchemy, redislab, mongo database, telethon, and pyrogram. How to set up/depl

IDNCoderX 42 Dec 21, 2022
Asynchronous multi-platform robot framework written in Python

NoneBot ✨ 跨平台 Python 异步机器人框架 ✨ 文档 · 安装 · 开始使用 · 文档打不开? 简介 NoneBot2 是一个现代、跨平台、可扩展的 Python 聊天机器人框架,它基于 Python 的类型注解和异步特性,能够为你的需求实现提供便捷灵活的支持。

NoneBot 3.1k Jan 04, 2023
Slam Mirror Bot is a multipurpose Telegram Bot written in Python for mirroring files on the Internet to our beloved Google Drive.

Slam Mirror Bot is a multipurpose Telegram Bot written in Python for mirroring files on the Internet to our beloved Google Drive.

Abinash939 1 Oct 10, 2021
This Is A Python Program To Showcase Two Modules (Gratient And Fade)

Hellooo, It's PndaBoi Here! This Is A Python Program To Showcase Two Modules (Gratient And Fade). I Really Like Both Of These Modules So I Decided To

PndaBoi! 6 May 31, 2022
Dashboard to monitor the performance of your Binance Futures account

futuresboard A python based scraper and dashboard to monitor the performance of your Binance Futures account. Note: A local sqlite3 database config/fu

86 Dec 29, 2022
Retrieve information from DBLP and update BibTex files automatically

Rebib TLDR: This script retrieves information from DBLP to update your BibTex files. python rebib.py --bibfile xxx.bib It first parses the bib entries

Shangtong Zhang 49 Jan 01, 2023
A simple url uploader bot with permenent thumbnail support

URL-Uploader A simple url uploader bot with permenent thumbnail support Scrapped some code from @SpEcHIDe's AnyDLBot Repository Please fork this repos

Fayas Noushad 40 Nov 29, 2021
Aria/qBittorrent Telegram mirror/leech bot.

Missneha Mirror Leech Bot Aria/qBittorrent Telegram mirror/leech bot. missneha Mirror Leech Bot is a multipurpose Telegram Bot written in Python for m

ACHAL 6 Sep 30, 2022
Fetch fund data from avanza.se using Python and some web scraping with bs4

Py(A)vanza Fetch fund data from avanza.se using Python and some web scraping with bs4. The default way is to display the data in the terminal, apply -

dunderrrrrr 1 Jan 27, 2022
Telegram Link Wayback Bot. This bot archives a web page thrown at itself with wayback Machine (Archive.org).

Telegram Link Wayback Bot. This bot archives a web page thrown at itself with wayback Machine (Archive.org).

Hüzünlü Artemis [HuzunluArtemis] 11 Feb 18, 2022