分组框图太窄而无法阅读

时间:2017-02-02 01:29:29

标签: python jupyter-notebook plotly

实际上一切正常:我尝试在一个图表中比较调查中的不同群体。因此我在Python(Jupyter-Notebook)中编写了以下代码

for value in values:
    catpool=getcat()
    py.offline.init_notebook_mode()
    data = []
    for cata in catpool:
        for con in constraints:
            data.append(  go.Box( y=getdf(value,cata,con[0])['Y'+value],x=con[1], name=cata, showlegend=False, boxmean='sd',
                             #boxpoints='all',
                             jitter=0.3,
                             pointpos=0 ) )
    layout=go.Layout(title="categorie: "+getclearname(value)+" - local space syntax measurements on placements<br>",yaxis=dict( title='percentage of range between flat extremes'),boxmode='group',showlegend=True)
    fig = go.Figure(data=data, layout=layout)
    py.offline.iplot(fig, filename='pandas-box-plot')

函数'getdf'从数据库中查询列

不幸的是,这导致了一个不可读的图表 a diagram with to narrow box plots 是否有可能给这些组减少间距,因此组中的箱图更多?还是其他任何可以让它更具可读性的东西?

谢谢

1 个答案:

答案 0 :(得分:0)

我自己解决了这个问题: 奇怪的行为发生了,因为for cata in catpool循环 - 组中的箱图数据必须包含数据框中的组值:所以我只是没有在这个地方循环,而是循环在串联中SQL语句。所以同样的查询被执行了,但是由#34; UNION&#34;像这样:

def formstmtelse (val, category, ext, constraint, nine=True):
    stmt=""
    if nine:
        matrix=['11','12','13','21','22','23','31','32','33']
    else:
        matrix=['11'] 
    j=0
    for cin in category:
        j=j+1
        if j>1:
            stmt=stmt+" UNION "
        m=0
        for cell in matrix:
            m=m+1
            if m>1:
                stmt=stmt+"""UNION 
                """
            stmt=stmt+"""SELECT '"""+cin+"""' AS cata,
            """
            if ext:
                stmt=stmt+"""((("""+val+"""-MIN"""+val+""")/(MAX"""+val+"""-MIN"""+val+"""))*100) AS Y"""+val
            else:
                stmt=stmt+"""((("""+val+""")/(MAX"""+val+"""))*100) AS Y"""+val
            stmt=stmt+""" 
            FROM `stests` 
            JOIN ssubject 
            ON ssubject.ssubjectID=stests.ssubjectID 
            JOIN scountries
            ON CountryGrownUpIn=scountriesID
            JOIN scontinents
            ON Continent=scontinentsID
            JOIN gridpoint 
            ON stests.FlatID=gridpoint.GFlatID AND G"""+cin+cell+"""=GIntID 
            JOIN 
            (
                SELECT GFlatID AS GSUBFlatID"""
            stmt=stmt+""",
            MAX("""+val+""") AS MAX"""+val+""",MIN("""+val+""") AS MIN"""+val
            stmt=stmt+"""
                FROM gridpoint 
                GROUP BY GSUBFlatID
            )
            AS virtualtable 
            ON FlatID=virtualtable.GSUBFlatID 
            """+constraint+" "
    return stmt

解决了这个问题。 &#39; x&#39;框调用的属性必须是列表或数据框,而不仅仅是单个字符串,即使字符串始终相同。我猜这是导致“看不见”的问题。使得自动缩放不可能的x值,或者换言之,具有新约束的每个查询的图例中的新点,并且对于每个类别,每个约束仅需要一个数据帧。更改此项时 - 可以通过将boxgroupgap或groupgab属性添加到布局来进行微调... 请原谅我的英文