2
votes

I have a dataset as below. I would like to plot a variability plot like in JMP with Grouped X-axis with multiple categories and legend by row. Example of dataset and Plot from JMP are below. Is there a Pythonic solution to plotting this type of data? I am looking for a solution using any of the python plotting libraries - bokeh,matplotlib,seaborn etc.

Please note that the Bottommost X-category must be horizontal in display while the sub-categories must be vertical. If this plotting could be flexible in handling the various X-axis categories (meaning if more are added in the future), that would be great.

This is a repost since its slightly different from my previous post about Grouped X-axis Var plot in Python.

Dataset and Example JMP plot below:

Sample DataSet

VarPlot Example - JMP

1

1 Answers

1
votes

Here is how I produced this grouped bar chart using the Altair plotting library. There are 2 limitations

  1. The column TEST_NAME is never the same from one row to the next, so it is not shown on the plot
  2. The column Date is the same always from one row to the next, so it is not shown on the plot

Imports

import altair as alt
import pandas as pd

Create the sample data

data = """
Name,Numbers,Date,TEST_NAME,Label,Data
ABC,404,201905,101,MEDIAN,0.745313
ABC,404,201905,102,NINETYFIVEPERC,1.03828
ABC,406,201905,103,MEDIAN,0.698438
ABC,406,201905,104,NINETYFIVEPERC,0.874219
ABC,408,201905,105,MEDIAN,0.721785
DEF,408,201905,106,NINETYFIVEPERC,1.05
DEF,411,201905,107,MEDIAN,0.7277345
DEF,411,201905,108,NINETYFIVEPERC,1.0083995
DEF,414,201905,109,MEDIAN,0.757031
DEF,414,201905,110,NINETYFIVEPERC,1.05
GHI,415,201905,111,MEDIAN,0.733594
GHI,415,201905,112,NINETYFIVEPERC,0.932813
GHI,441,201905,113,MEDIAN,0.745313
GHI,441,201905,114,NINETYFIVEPERC,0.96738305
GHI,498,201905,115,MEDIAN,0.721875
"""
df = pd.read_csv(pd.compat.StringIO(data), sep=',')

Show data

print(df)

   Name  Numbers    Date  TEST_NAME           Label      Data
0   ABC      404  201905        101          MEDIAN  0.745313
1   ABC      404  201905        102  NINETYFIVEPERC  1.038280
2   ABC      406  201905        103          MEDIAN  0.698438
3   ABC      406  201905        104  NINETYFIVEPERC  0.874219
4   ABC      408  201905        105          MEDIAN  0.721785
5   DEF      408  201905        106  NINETYFIVEPERC  1.050000
6   DEF      411  201905        107          MEDIAN  0.727735
7   DEF      411  201905        108  NINETYFIVEPERC  1.008400
8   DEF      414  201905        109          MEDIAN  0.757031
9   DEF      414  201905        110  NINETYFIVEPERC  1.050000
10  GHI      415  201905        111          MEDIAN  0.733594
11  GHI      415  201905        112  NINETYFIVEPERC  0.932813
12  GHI      441  201905        113          MEDIAN  0.745313
13  GHI      441  201905        114  NINETYFIVEPERC  0.967383
14  GHI      498  201905        115          MEDIAN  0.721875

Generate grouped bar chart

alt.Chart(df).mark_circle(size=100).encode(
    x='Numbers:O',
    y='Data',
    color='Label',
    column='Name'
)

Here is the resulting plot Chart