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
| # 2 Change background and font color | |
| # Create object of figure | |
| fig = go.Figure() | |
| # Create a bar plot | |
| fig.add_trace( | |
| go.Bar( | |
| x = df['Fruit'], | |
| y = df['Sales'] |
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
| # 3 Sort the bar in descending order | |
| # Sort the data frame by sales | |
| df.sort_values( | |
| by = ['Sales'], | |
| ascending = False, | |
| ignore_index = True, | |
| inplace = True | |
| ) |
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
| # 4 Set a bar width | |
| # Create list of bar width | |
| widths = np.repeat(0.5, len(df)) | |
| # Create object of figure | |
| fig = go.Figure() | |
| # Create a bar plot | |
| fig.add_trace( |
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
| # 5 Flip the horizontal axis and set range of vertical axis | |
| # Create object of figure | |
| fig = go.Figure() | |
| # Create a bar plot | |
| fig.add_trace( | |
| go.Bar( | |
| x = df['Fruit'], | |
| y = df['Sales'], |
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'], |
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
| # 7 Highlight some points in bar | |
| # Add the colors | |
| avg_sales = df['Sales'].mean() | |
| df['Color'] = df['Sales'].apply(lambda x: '#981220' if x >= avg_sales else '#80797C') | |
| # Create object of figure | |
| fig = go.Figure() | |
| # Create a bar plot |
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
| # 8 Add the horizontal line | |
| # Create object of figure | |
| fig = go.Figure() | |
| # Create a bar plot | |
| fig.add_trace( | |
| go.Bar( | |
| x = df['Fruit'], | |
| y = df['Sales'], |
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
| # 9 Modify the hover text | |
| # Create object of figure | |
| fig = go.Figure() | |
| # Create a bar plot | |
| fig.add_trace( | |
| go.Bar( | |
| x = df['Fruit'], | |
| y = df['Sales'], |
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
| # 10 Add multiple plot into one frame | |
| # Calculate the accumulated percentage | |
| df['Percentage'] = (df['Sales'].cumsum() / df['Sales'].sum()) * 100 | |
| # Create object of figure | |
| fig = make_subplots( | |
| specs = [ | |
| [ | |
| { |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.