Code Monkey home page Code Monkey logo

stackedbargraph's Introduction

stackedBarGraph

Overview

Code for making purdy stacked bar graphs. I really needed this one day so searching online for an answer I found only this question: https://stackoverflow.com/questions/19060144/more-efficient-matplotlib-stacked-bar-chart-how-to-calculate-bottom-values. So I wrote this. There is more stacked-bar-graph-esque goodness at the above link.

Installation

Copy and paste at will

Usage

The file contains one Class called 'StackedBarGrapher' which contains one useful function called 'stackedBarPlot'.

Its required arguments are:

ax                  # pyplot axes to plot onto
data                # data to plot  --> A list of lists of FLOATS.
cols                # colors for each level in the stack

Optional arguments:

xLabels             # bar specific labels
yTicks              # information used for making y ticks ["none", <int> or [[tick_pos1, tick_pos2, ... ],[tick_label_1, tick_label2, ...]]
edgeCols            # colors for edges
showFirst           # only plot the first <showFirst> bars
scale               # scale bars to same height
widths              # set widths for each bar
heights             # set heights for each bar
ylabel              # label for x axis
xlabel              # label for y axis
gap                 # all a gap between the bars (use a float, default = 0. i.e. no gap)
endGaps             # allow gaps at end of bar chart (only used if gaps != 0.) True or False (default = False)

Example usage 1

from stackedBarGraph import StackedBarGrapher()
SBG = StackedBarGrapher()
SBG.demo()

Example usage 2

import numpy as np
from matplotlib import pyplot as plt
from stackedBarGraph import StackedBarGrapher
SBG = StackedBarGrapher()

d = np.array([[101.,0.,0.,0.,0.,0.,0.],
              [92.,3.,0.,4.,5.,6.,0.],
              [56.,7.,8.,9.,23.,4.,5.],
              [81.,2.,4.,5.,32.,33.,4.],
              [0.,45.,2.,3.,45.,67.,8.],
              [99.,5.,0.,0.,0.,43.,56.]])

d_widths = [.5,1.,3.,2.,1.,2.]
d_labels = ["fred","julie","sam","peter","rob","baz"]
d_colors = ['#2166ac', '#fee090', '#fdbb84', '#fc8d59', '#e34a33', '#b30000', '#777777']
fig = plt.figure()

ax = fig.add_subplot(111)
SBG.stackedBarPlot(ax,
                   d,
                   d_colors,
                   xLabels=d_labels,
                   yTicks=7,
                   widths=d_widths,
                   scale=True
                  )
plt.title("Scaled bars with set widths")

fig.subplots_adjust(bottom=0.4)
plt.tight_layout()
plt.show()
plt.close(fig)
del fig

Help

If you experience any problems using stackedBarGraph, open an issue on GitHub and tell us about it.

Licence and referencing

GPLv3 with love. Project home page, info on the source tree, documentation, issues and how to contribute, see http://github.com/minillinim/stackedBarGraph

Copyright

Copyright (c) 2014-2017 Michael Imelfort. See LICENSE.txt for further details.

stackedbargraph's People

Contributors

minillinim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

stackedbargraph's Issues

How to make plot bigger?

Hi!
I like yr module very much,
its very useful.
But how to make plot bigger? For example:1200px x 2000px

Legend

How do you create a legend indicating what each color represents?

Nice work + doubt

Hey man,
Nice work, really, something that in matplotlib seems burocratic you really speed up the things.
(thinking right now, did you expose you lib to the matplotlib devel team? I think your work will help a lot more people)

Well, my doubt is I wonder if there is a simple way of display the data with the real numbers stacked instead the proportion among them? Later I will study your code and check but now is late and I'm tired =|

Update print

Please update the print function with round brackets for newer versions.

LG Chri

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.