我有一个数据集如下。我想绘制一个像JMP中的可变性图,其中Grouped X-axis有多个类别和行的图例。数据集的示例和JMP的绘图如下。是否有Pythonic解决方案来绘制此类数据?我正在寻找使用任何python绘图库的解决方案 - 散景,matplotlib,seaborn等。
请注意,最底层的X类别必须是水平显示,而子类别必须是垂直的。如果这种绘图可以灵活地处理各种X轴类别(意味着如果将来添加更多),那将是很好的。
这是一个重新发布,因为它与我之前关于Python中的分组X轴Var图的文章略有不同。
下面的数据集和示例JMP图:
以下是我使用Altair绘图库生成此分组条形图的方法。有2个限制
TEST_NAME
从一行到下一行永远不会相同,所以它没有显示在图上Date
始终从一行到下一行,因此它未在图中显示进口
import altair as alt
import pandas as pd
Create样本数据
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=',')
显示数据
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
生成分组条形图
alt.Chart(df).mark_circle(size=100).encode(
x='Numbers:O',
y='Data',
color='Label',
column='Name'
)