Skip to content

Instantly share code, notes, and snippets.

View audhiaprilliant's full-sized avatar
🎯
Focusing

Audhi Aprilliant audhiaprilliant

🎯
Focusing
View GitHub Profile
@audhiaprilliant
audhiaprilliant / introduction-plotly-3.py
Created March 7, 2022 00:54
Introduction to Plotly
# 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']
@audhiaprilliant
audhiaprilliant / introduction-plotly-4.py
Created March 7, 2022 00:56
Introduction to Plotly
# 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
)
@audhiaprilliant
audhiaprilliant / introduction-plotly-5.py
Created March 7, 2022 00:57
Introduction to Plotly
# 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(
@audhiaprilliant
audhiaprilliant / introduction-plotly-6.py
Last active March 7, 2022 08:27
Introduction to Plotly
# 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'],
@audhiaprilliant
audhiaprilliant / introduction-plotly-7.py
Last active March 7, 2022 01:03
Introduction to Plotly
# 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'],
@audhiaprilliant
audhiaprilliant / introduction-plotly-8.py
Created March 7, 2022 01:04
Introduction to Plotly
# 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
@audhiaprilliant
audhiaprilliant / introduction-plotly-9.py
Created March 7, 2022 01:05
Introduction to Plotly
# 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'],
@audhiaprilliant
audhiaprilliant / introduction-plotly-10.py
Created March 7, 2022 01:06
Introduction to Plotly
# 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'],
@audhiaprilliant
audhiaprilliant / introduction-plotly-11.py
Created March 7, 2022 01:08
Introduction to Plotly
# 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 = [
[
{
@audhiaprilliant
audhiaprilliant / introduction-plotly.ipynb
Created March 7, 2022 01:13
Introduction to Plotly
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.