DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Languages
  4. Creating Graphs With Python and GooPyCharts

Creating Graphs With Python and GooPyCharts

If you are looking for something that’s super easy to install and use, and you don’t mind the small set of charts it supports, then GooPyCharts may be just the right package for you.

Mike Driscoll user avatar by
Mike Driscoll
·
Oct. 31, 16 · Tutorial
Like (1)
Save
Tweet
Share
4.35K Views

Join the DZone community and get the full member experience.

Join For Free

over the summer, i came across an interesting plotting library called goopycharts which is a python wrapper for the google charts api. in this article, we will spend a few minutes learning how to use this interesting package. goopycharts follows syntax that is similar to matlab and is actually meant to be an alternative to matplotlib.

to install goopycharts, all you need to do is use pip like this:

pip install gpcharts

now that we have it installed, we can give it a whirl!

our first graph

using goopycharts to create a chart or graph is extremely easy. in fact, you can create a simple graph in 3 lines of code:

>>> from gpcharts import figure
>>> my_plot = figure(title='demo')
>>> my_plot.plot([1, 2, 10, 15, 12, 23])

if you run this code, you should see your default browser pop open with the following image displayed:

gpchart_simple

you will note that you can download the figure as a png or save the data that made the chart as a csv file. goopycharts also integrates with the jupyter notebook.

creating a bar graph

the goopycharts package has a nice testgraph.py script included to help you learn how to use the package. unfortunately, it doesn’t actually demonstrate different types of charts. so i took one of the examples from there and modified it to create a bar chart:

from gpcharts import figure

fig3 = figure()
xvals = ['temps','2016-03-20','2016-03-21','2016-03-25','2016-04-01']
yvals = [['shakuras','korhal','aiur'],[10,30,40],[12,28,41],[15,34,38],[8,33,47]]

fig3.title = 'weather over days'
fig3.ylabel = 'dates'
fig3.bar(xvals, yvals)

you will note that in this example we create our title using the figure instance’s title property. we also set the ylabel the same way. you can also see how to define dates for the chart as well as set an automatic legend using nested lists. finally, you can see that instead of calling plot we need to call bar to generate a bar chart. here is the result:

weather

creating other types of graphs

let’s modify the code a bit more and see if we can create other types of graphs. we will start with a scatter plot:

from gpcharts import figure

my_fig = figure()
xvals = ['dates','2016-03-20','2016-03-21','2016-03-25','2016-04-01']
yvals = [['shakuras','korhal','aiur'],[10,30,40],[12,28,41],[15,34,38],[8,33,47]]

my_fig.title = 'scatter plot'
my_fig.ylabel = 'temps'

my_fig.scatter(xvals, yvals)

here we can most of the same data that we used in the last example. we just need to modify a few values to make the x and y labels work correctly and we need to title the graph with something that makes sense. when you run this code, you should see something like this:

scatter

that was pretty simple. let’s try creating a quick and dirty histogram:

from gpcharts import figure

my_fig = figure()
my_fig.title = 'random histrogram'
my_fig.xlabel = 'random values'
vals = [10, 40, 30, 50, 80, 100, 65]
my_fig.hist(vals)

the histogram is much simpler than the last two charts we created as it only needs one list of values to create it successfully. this is what i got when i ran the code:

histogram

this is a pretty boring looking histogram, but it’s extremely easy to modify it and add a more realistic set of data.

wrapping up

while this was just a quick run-through of some of goopycharts capabilities, i think we got a pretty good idea of what this charting package is capable of. it’s really easy to use, but only has a small set of charts to work with. pygal , bokeh, and matplotlib have many other types of charts that they can create. however, if you are looking for something that’s super easy to install and use and you don’t mind the small set of charts it supports, then goopycharts may be just the right package for you!

Chart Python (language)

Published at DZone with permission of Mike Driscoll, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How Observability Is Redefining Developer Roles
  • How To Convert HTML to PNG in Java
  • (Deep) Cloning Objects in JavaScript
  • Educating the Next Generation of Cloud Engineers With Google Cloud

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: