https://github.com/kartmaan/plotly-intervals
Group values from a Pandas Series according to given intervals and represent them graphically with Plotly
https://github.com/kartmaan/plotly-intervals
bar-chart grouping grouping-plots intervals intervals-chart numpy numpy-arrays orca pandas pandas-series percentile pie-chart plot plotly plotting values
Last synced: 7 months ago
JSON representation
Group values from a Pandas Series according to given intervals and represent them graphically with Plotly
- Host: GitHub
- URL: https://github.com/kartmaan/plotly-intervals
- Owner: Kartmaan
- License: mit
- Created: 2022-11-11T22:00:13.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-29T14:06:09.000Z (over 2 years ago)
- Last Synced: 2025-01-24T07:29:59.795Z (9 months ago)
- Topics: bar-chart, grouping, grouping-plots, intervals, intervals-chart, numpy, numpy-arrays, orca, pandas, pandas-series, percentile, pie-chart, plot, plotly, plotting, values
- Language: Python
- Homepage:
- Size: 36.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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)
```
**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')
```
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')
```
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')
```