File size: 2,781 Bytes
e88abf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import solara
import numpy as np
import plotly.express as px
from utils import selected_template


@solara.component
def Histograms():

    with solara.Column(gap="20px", align = "stretch") as main:
        
        solara.Markdown(f"#HISTOGRAMS")

        # Plot histogram based on rolling 2 dice
        dice_1 = np.random.randint(1,7,5000)
        dice_2 = np.random.randint(1,7,5000)
        dice_sum = dice_1 + dice_2
        # bins represent the number of bars to make
        # Can define x label, color, title
        # marginal creates another plot (violin, box, rug)
        fig1 = px.histogram(dice_sum, nbins=11, labels={'value':'Dice Roll'},
                    title='5000 Dice Roll Histogram', marginal='violin',
                    color_discrete_sequence=['green'])

        fig1.update_layout(
            xaxis_title_text='Dice Roll',
            yaxis_title_text='Dice Sum',
            bargap=0.2, showlegend=False,
            template=selected_template.value
        )

        solara.Markdown(f"#### Plot histogram based on rolling 2 dice ")
        solara.Markdown("""
                        ```python
                            dice_1 = np.random.randint(1,7,5000)
                            dice_2 = np.random.randint(1,7,5000)
                            dice_sum = dice_1 + dice_2
                            # bins represent the number of bars to make
                            # Can define x label, color, title
                            # marginal creates another plot (violin, box, rug)
                            fig1 = px.histogram(dice_sum, nbins=11, labels={'value':'Dice Roll'},
                                        title='5000 Dice Roll Histogram', marginal='violin',
                                        color_discrete_sequence=['green'])

                            fig1.update_layout(
                                xaxis_title_text='Dice Roll',
                                yaxis_title_text='Dice Sum',
                                bargap=0.2, showlegend=False
                            )
                        ```
                        """
                        )
        solara.FigurePlotly(fig1)



        # Stack histograms based on different column data
        df_tips = px.data.tips()
        fig2= px.histogram(df_tips, x="total_bill", color="sex",template=selected_template.value)


        solara.Markdown(f"####Stack histograms based on different column data")
        solara.Markdown("""
                        ```python
                            df_tips = px.data.tips()
                            px.histogram(df_tips, x="total_bill", color="sex")
                        ```
                        """
                        )
        solara.FigurePlotly(fig2)
        
    return main