def polarChart(df):
     type_of_plot = st.selectbox("Select Type of Plot",["POLAR1","POLAR2","POLAR3 Angle"])
     all_columns = df.columns
    
        
        #st.success("Generating Customizable Plot of {} for {}".format(type_of_plot))
        
     if type_of_plot == 'POLAR1':
           
            columns_to_plot = st.selectbox("Select 1 column",all_columns,key='a' )
            
            columns_to_plot1 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot]], key='b' )
        # columns_to_plot2 = st.selectbox("Select 1 column",all_columns, key='c' )
            n = df[[columns_to_plot, columns_to_plot1]].sort_values(by = columns_to_plot1 , ascending = True)
            cje = n[columns_to_plot].tolist()
            other_var = n[columns_to_plot1].tolist()
          
           
            # cje = df[columns_to_plot].tolist()
            # other_var = df[columns_to_plot1].sort_values(ascending = True).tolist()
        # other_var1 = df[columns_to_plot2].tolist()
            polar = Polar()
            polar.add_schema( 
       radiusaxis_opts=opts.RadiusAxisOpts( data = cje ,type_="category",
                                                splitline_opts=opts.SplitLineOpts(is_show=False),
                                                axisline_opts=opts.AxisLineOpts(is_show=False),
                                                axistick_opts=opts.AxisTickOpts(is_show=False)),
            angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True,
                                              splitline_opts=opts.SplitLineOpts(is_show=False),
                                              axisline_opts=opts.AxisLineOpts(is_show=False),
                                              axislabel_opts=opts.LabelOpts(is_show=False),
                                              axistick_opts=opts.AxisTickOpts(is_show=False)))
            polar.add(columns_to_plot1, other_var, type_="bar")
            polar.set_global_opts(toolbox_opts=opts.ToolboxOpts())
            polar.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='inside', font_size=8,
                                                            font_weight='bold'))
                             
            return polar
        
        
        
     if type_of_plot == 'POLAR2':
            columns_to_plot = st.selectbox("Select 1 column",all_columns,key='a' )
            columns_to_plot1 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot]], key='b' )
            columns_to_plot2 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot1, columns_to_plot]], key='c' )
            columns_to_plot3 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot1, columns_to_plot2,columns_to_plot]], key='c' )
            columns_to_plot4 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot1, columns_to_plot2,columns_to_plot, columns_to_plot3]], key='c' )
            n = df[[columns_to_plot, columns_to_plot1, columns_to_plot2, columns_to_plot3, columns_to_plot4]].sort_values(by = columns_to_plot1 , ascending = True)
            
            cje = n[columns_to_plot].tolist()
            other_var = n[columns_to_plot1].tolist()
            other_var2 = n[columns_to_plot2].tolist()
            other_var3 = n[columns_to_plot3].tolist()
            other_var4 = n[columns_to_plot4].tolist()
          

            polar = Polar()
            polar.add_schema( 
       radiusaxis_opts=opts.RadiusAxisOpts( data = cje ,type_= "category",
                                                splitline_opts=opts.SplitLineOpts(is_show=False),
                                                axisline_opts=opts.AxisLineOpts(is_show=False),
                                                axistick_opts=opts.AxisTickOpts(is_show=False)),
            angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True,
                                              splitline_opts=opts.SplitLineOpts(is_show=False),
                                              axisline_opts=opts.AxisLineOpts(is_show=False),
                                              axislabel_opts=opts.LabelOpts(is_show=False),
                                              axistick_opts=opts.AxisTickOpts(is_show=False)))
            polar.add(columns_to_plot1, other_var, type_="bar" )
            polar.add(columns_to_plot2, other_var2, type_="bar")
            polar.add(columns_to_plot3, other_var3, type_="bar")
            polar.add(columns_to_plot4, other_var4, type_="bar")
            polar.set_global_opts(toolbox_opts=opts.ToolboxOpts(),)
            polar.set_series_opts(label_opts=opts.LabelOpts(is_show=True))
       
            return polar
        
     if type_of_plot == 'POLAR3 Angle':
            columns_to_plot = st.selectbox("Select 1 column",all_columns,key='a' )
            columns_to_plot1 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot]], key='b' )
            columns_to_plot2 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot1, columns_to_plot]], key='c' )
            columns_to_plot3 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot1, columns_to_plot2,columns_to_plot]], key='c' )
            columns_to_plot4 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot1, columns_to_plot2,columns_to_plot, columns_to_plot3]], key='c' )
            n = df[[columns_to_plot, columns_to_plot1, columns_to_plot2, columns_to_plot3, columns_to_plot4]].sort_values(by = columns_to_plot1 , ascending = True)
            
            cje = n[columns_to_plot].tolist()
            other_var = n[columns_to_plot1].tolist()
            other_var2 = n[columns_to_plot2].tolist()
            other_var3 = n[columns_to_plot3].tolist()
            other_var4 = n[columns_to_plot4].tolist()
          

            polar = Polar()
            polar.add_schema( 
    #    radiusaxis_opts=opts.RadiusAxisOpts( data = cje ,type_= "category",
    #                                             splitline_opts=opts.SplitLineOpts(is_show=False),
    #                                             axisline_opts=opts.AxisLineOpts(is_show=False),
    #                                             axistick_opts=opts.AxisTickOpts(is_show=False)),
            angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True,type_= "category",
                                              splitline_opts=opts.SplitLineOpts(is_show=False),
                                              axisline_opts=opts.AxisLineOpts(is_show=False),
                                              axislabel_opts=opts.LabelOpts(is_show=False),
                                              axistick_opts=opts.AxisTickOpts(is_show=False)))
            polar.add(columns_to_plot1, other_var, type_="bar", stack="stack0" )
            polar.add(columns_to_plot2, other_var2, type_="bar" , stack="stack0")
            polar.add(columns_to_plot3, other_var3, type_="bar" , stack="stack0")
            polar.add(columns_to_plot4, other_var4, type_="bar" , stack="stack0")
            polar.set_global_opts(toolbox_opts=opts.ToolboxOpts())
            polar.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
       
            return polar
예제 #2
0
boxplot.render_notebook()

# %% [markdown]
# ### Polar -- 极坐标

import math
data=[]
# 生成数据,满足格式`[r, \theta]`,即可以认为角度为自变量、径向为因变量
for i in range(0, 360):
    data.append([100 * math.sin(i/180 * math.pi), i])
polar = Polar()
polar.add("", data)
# 调整角度坐标轴样式
polar.add_schema(
    angleaxis_opts=opts.AngleAxisOpts(
        interval=90,
        max_=360
    )
)
polar.render_notebook()

# %% [markdown]
# #### 极坐标柱状图

polar = Polar()
polar.add("", list(zip(Faker.choose(), Faker.values())), type_="bar")
polar.add_schema(
    radiusaxis_opts=opts.RadiusAxisOpts(type_="category"),
    angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True)
)
polar.render_notebook()