Untitled

Anonymous
plain_text
09/02/2026 12:45 PM
2.0 KB
4
Indexable
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

# Persiapan data
df = pd.read_csv('retail_raw_reduced.csv')
df['order_date'] = pd.to_datetime(df['order_date'])

data_dec = (
    df[df['order_date'].dt.to_period('M') == '2019-12']
    .groupby('order_date')['customer_id']
    .nunique()
)

# Grafik
plt.style.use('seaborn-v0_8-whitegrid')
fig, ax = plt.subplots(figsize=(10, 5))

ax.plot(
    data_dec.index,
    data_dec.values,
    color='#2E86AB',
    marker='o',
    linewidth=2,
    markersize=5
)

ax.fill_between(
    data_dec.index,
    data_dec.values,
    color='#2E86AB',
    alpha=0.12
)

# Tandai nilai tertinggi dan terendah
for date, color, label in [
    (data_dec.idxmax(), '#F18F01', 'Tertinggi'),
    (data_dec.idxmin(), '#C73E1D', 'Terendah')
]:
    value = data_dec[date]
    ax.scatter(date, value, color=color, s=80, zorder=3)
    ax.annotate(
        f'{label}: {value}',
        (date, value),
        xytext=(0, 12 if label == 'Tertinggi' else -20),
        textcoords='offset points',
        ha='center',
        color=color,
        fontweight='bold'
    )

# Format grafik
ax.xaxis.set_major_locator(mdates.DayLocator(interval=3))
ax.xaxis.set_major_formatter(mdates.DateFormatter('%d %b'))

ax.set(
    title='Jumlah Pembeli Unik Harian — Desember 2019',
    xlabel='Tanggal Pembelian',
    ylabel='Jumlah Customer Unik',
    ylim=(0, None)
)

ax.grid(linestyle='--', alpha=0.5)
ax.spines[['top', 'right']].set_visible(False)

plt.xticks(rotation=0)
plt.tight_layout()
plt.show()
Editor is loading...
Leave a Comment