File size: 8,647 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import solara
import plotly.express as px
import plotly.graph_objects as go
from utils import selected_template

@solara.component
def LinePlot():

    with solara.Column(gap="20px", align = "stretch") as main:
        
        solara.Markdown(f"#LINE PLOTS")
        
        df_stocks = px.data.stocks()
        fig1 = px.line(df_stocks, x='date', y='GOOG', labels={'x':'Date', 'y':'Price'},
                    template=selected_template.value
                    )
        solara.Markdown(f"###Use included Google price data to make one plot")
        
        solara.Markdown("""
                        ```python
                        fig1 = px.line(df_stocks, x='date', y='GOOG', labels={'x':'Date', 'y':'Price'},
                        template=selection_data.value)
                        ```
                        """
                        )
                        
                        

        solara.FigurePlotly(fig1)
        
        all_stocks =df_stocks.columns.values.tolist()
        del all_stocks[0]
        stocks,set_stocks = solara.use_state ([all_stocks[0],all_stocks[1]])

        fig2 = px.line(df_stocks, x='date', y=stocks, labels={'x':'Date', 'y':'Price'},
            title=" VS ".join(stocks),
            template=selected_template.value)

        with solara.Card():
            solara.Markdown(f"###Make multiple line plots")
            
            solara.Markdown("""
                            ```python
                            fig2 = px.line(df_stocks, x='date', y=['GOOG','AAPL'], labels={'x':'Date', 'y':'Price'},
                                title='Apple Vs. Google',template=selection_data.value)
                            ```
                            """
                            )
            
            solara.FigurePlotly(fig2)
            solara.SelectMultiple("Stocks", values= stocks, all_values= all_stocks, on_value =set_stocks)


        # Create a figure to which I'll add plots
        fig3 = go.Figure()
        # You can pull individual columns of data from the dataset and use markers or not
        fig3.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.AAPL, 
                                mode='lines', name='Apple'))
        fig3.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.AMZN, 
                                mode='lines+markers', name='Amazon'))
        # You can create custom lines (Dashes : dash, dot, dashdot)
        fig3.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.GOOG, 
                                mode='lines+markers', name='Google',
                                line=dict(color='firebrick', width=2, dash='dashdot')))
        fig3.update_layout(template= selected_template.value)

        solara.Markdown(f"###Create a figure to which I'll add plots")
        
        solara.Markdown("""
                        ```python
                            fig3 = go.Figure()
                            # You can pull individual columns of data from the dataset and use markers or not
                            fig3.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.AAPL, 
                                                    mode='lines', name='Apple'))
                            fig3.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.AMZN, 
                                                    mode='lines+markers', name='Amazon'))
                            # You can create custom lines (Dashes : dash, dot, dashdot)
                            fig3.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.GOOG, 
                                                    mode='lines+markers', name='Google',
                                                    line=dict(color='firebrick', width=2, dash='dashdot')))
                        ```
                        """
                        )
        
        solara.FigurePlotly(fig3)


        solara.Markdown(f"###Go crazy styling the figure")

        fig4 =  go.Figure()
        # You can pull individual columns of data from the dataset and use markers or not
        fig4.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.AAPL, 
                                mode='lines', name='Apple'))
        fig4.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.AMZN, 
                                mode='lines+markers', name='Amazon'))
        # You can create custom lines (Dashes : dash, dot, dashdot)
        fig4.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.GOOG, 
                                mode='lines+markers', name='Google',
                                line=dict(color='firebrick', width=2, dash='dashdot')))
        fig4.update_layout(template= selected_template.value)
        fig4.update_layout(
            # Shows gray line without grid, styling fonts, linewidths and more
                xaxis=dict(
                    showline=True,
                    showgrid=False,
                    showticklabels=True,
                    linecolor='rgb(204, 204, 204)',
                    linewidth=2,
                    ticks='outside',
                    tickfont=dict(
                        family='Arial',
                        size=12,
                        color='rgb(82, 82, 82)',
                    ),
                ),
                # Turn off everything on y axis
                yaxis=dict(
                    showgrid=False,
                    zeroline=False,
                    showline=False,
                    showticklabels=False,
                ),
                # autosize=False,
                margin=dict(
                    autoexpand=False,
                    l=100,
                    r=20,
                    t=110,
                ),
                showlegend=False,
                plot_bgcolor='white'
            )
        
        solara.Markdown("""
                ```python
                    fig4 =  go.Figure()
                            # You can pull individual columns of data from the dataset and use markers or not
                            fig4.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.AAPL, 
                                                    mode='lines', name='Apple'))
                            fig4.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.AMZN, 
                                                    mode='lines+markers', name='Amazon'))
                            # You can create custom lines (Dashes : dash, dot, dashdot)
                            fig4.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.GOOG, 
                                                    mode='lines+markers', name='Google',
                                                    line=dict(color='firebrick', width=2, dash='dashdot')))
                            fig4.update_layout(template= selection_data.value)
                            fig4.update_layout(
                                # Shows gray line without grid, styling fonts, linewidths and more
                                    xaxis=dict(
                                        showline=True,
                                        showgrid=False,
                                        showticklabels=True,
                                        linecolor='rgb(204, 204, 204)',
                                        linewidth=2,
                                        ticks='outside',
                                        tickfont=dict(
                                            family='Arial',
                                            size=12,
                                            color='rgb(82, 82, 82)',
                                        ),
                                    ),
                                    # Turn off everything on y axis
                                    yaxis=dict(
                                        showgrid=False,
                                        zeroline=False,
                                        showline=False,
                                        showticklabels=False,
                                    ),
                                    # autosize=False,
                                    margin=dict(
                                        autoexpand=False,
                                        l=100,
                                        r=20,
                                        t=110,
                                    ),
                                    showlegend=False,
                                    plot_bgcolor='white'
                                )
                ```
                """
                )
        solara.FigurePlotly(fig4)
    
    return main