Last active
March 7, 2022 01:03
-
-
Save audhiaprilliant/ca14c87054ae7927caf6eba60b82f942 to your computer and use it in GitHub Desktop.
Introduction to Plotly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 6 Add plot title, subtitle, description, footnote, and axis titles | |
| # Create object of figure | |
| fig = go.Figure() | |
| # Create a bar plot | |
| fig.add_trace( | |
| go.Bar( | |
| x = df['Fruit'], | |
| y = df['Sales'], | |
| width = widths | |
| ) | |
| ) | |
| # Config for title, background, legend etc | |
| fig.update_layout( | |
| plot_bgcolor = 'white', | |
| font = { | |
| 'color': '#797979' | |
| }, | |
| xaxis = { | |
| 'title': '<b>Fruit</b>', | |
| 'linecolor': '#FFFFFF' | |
| }, | |
| yaxis = { | |
| 'title': '<b>Sales</b>', | |
| 'linecolor': '#FFFFFF' | |
| } | |
| ) | |
| # Flip the horizontal axis | |
| fig.update_xaxes( | |
| tickangle = 270 | |
| ) | |
| # Set range of vertical axis | |
| fig.update_yaxes( | |
| range = [0, 30000] | |
| ) | |
| # Add title | |
| fig.add_annotation( | |
| text = '<b><span style="color:#981220">Fruit with the most sales</span></b><span style="color:#797979"> in Fresh Fruit Store, 2021</span>', | |
| xref = 'paper', | |
| yref = 'paper', | |
| x = -0.095, | |
| y = 1.325, | |
| showarrow = False, | |
| align = 'left', | |
| xanchor = 'left', | |
| font = { | |
| 'size': 18, | |
| 'color': '#242526' | |
| } | |
| ) | |
| # Add subtitle | |
| fig.add_annotation( | |
| text = 'Data is from 5th January to 24th December 2021', | |
| xref = 'paper', | |
| yref = 'paper', | |
| x = -0.095, | |
| y = 1.24, | |
| showarrow = False, | |
| align = 'left', | |
| xanchor = 'left', | |
| font = { | |
| 'size': 11 | |
| } | |
| ) | |
| # Add description | |
| fig.add_annotation( | |
| text = "In 2021, bananas become the most favorite fruit, as 25,750 units were sold or about 18.9%. The number of sales for bananas and apples are<br>quite gaping, where 15,750 apples were sold. The rest of fruits sold at 10,000 to 14,500 units in 2021 with an average of around 11,800 units", | |
| xref = 'paper', | |
| yref = 'paper', | |
| x = -0.095, | |
| y = 1.175, | |
| showarrow = False, | |
| align = 'left', | |
| xanchor = 'left', | |
| font = { | |
| 'size': 13, | |
| 'color': '#242526' | |
| } | |
| ) | |
| # Show graph | |
| fig.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment