GithubHelp home page GithubHelp logo

kartmaan / plotly_intervals Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 37 KB

Group values from a Pandas Series according to given intervals and represent them graphically with Plotly

License: MIT License

Python 100.00%
bar-chart grouping intervals intervals-chart orca pie-chart plotly numpy numpy-arrays pandas pandas-series grouping-plots values plot plotting percentile

plotly_intervals's Introduction

plotly_intervals

A function that groups values from a Pandas Series according to given intervals and represent them graphically in the form of bar chart or pie chart with Plotly. Serval parameters can be adjusted :

  • The plot title
  • x/y axis labels
  • The intervals chosen for the grouping of values (example: [[0,5], [5,10], ...]
  • If no interval is defined, default intervals will be generated from the values present in the Pandas Series
  • Display a last interval grouping all the values greater than the last given interval
  • The plot kind (bar chart or pie chart)
  • Grid display
  • Choice of bar color for bar chart
  • The output (static/non-interactive image, interactive figure, plotly Figure object, bytes, intervals dictionnary)

Exemples

For this example we will use a dataset on exoplanets and recover in the form of Pandas Series the column relating to the distance of planetary systems from us :

dist = df['sy_dist']

To start we will simply insert the Series into the function without adding any parameters :

plot_group(dist)

dist

Intervals have been defined automatically by the function based on the values present in the Series and their dispersion (see the comments in the function for more information).

Now let's relaunch the function but adding some parameters and, in particular, custom intervals.

# Custom intervals
inter = [[0,25], [25,50], [75,100], [100,125], [125,150]]

plot_group(dist,
intervals = inter, 
title='Distance of exoplanets from us', 
x_label='Distance [parsec]',
y_label='Number of exoplanets',
bar_color='#b4522b')

dist_inter

The higher_vals parameter allows to add a last interval grouping all the values of the Series greater than the last interval provided

# Custom intervals
inter = [[0,400], [400,800], [800,1200]]

plot_group(dist,
intervals = inter,
higher_vals=True,
title='Distance of exoplanets from us', 
x_label='Distance [parsec]',
y_label='Number of exoplanets',
bar_color='#b4522b')

dist_high

The representation can also be done in the form of a pie chart :

inter = [[0,400], [400,800], [800,1200]]

plot_group(dist,
kind='pie_hole',
intervals = inter,
higher_vals=True, 
title='Distance of exoplanets from us')

dist_pie

plotly_intervals's People

Contributors

kartmaan avatar

Watchers

 avatar

plotly_intervals's Issues

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.