1. Why Customize
Default plots work for exploration. Client reports need controlled ticks, rotated labels, clear legends, and high-DPI exports.
2. Three Pillars
- Ticks — explicit axis intervals (e.g.
range(0, 11, 2))
- Label rotation — angle long categories or dense numbers (30° / 45°)
- Legend placement — e.g.
loc="upper right" so the box does not cover data
3. Sine Wave + 300 DPI Export
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 50)
y = np.sin(x)
fig, ax = plt.subplots(figsize=(6, 4))
ax.plot(x, y, label="sin(x)", color="blue", linewidth=2)
ax.set_xticks(range(0, 11, 2))
ax.tick_params(axis="x", labelrotation=30)
ax.legend(loc="upper right")
ax.set_title("Customized Sine Wave Plot")
plt.tight_layout()
fig.savefig("sin_plot.png", dpi=300)
plt.show()
dpi=300 produces print-ready sharpness; screens often show ~72–100 DPI.
4. Payment Methods Bar Chart
import pandas as pd
df = pd.read_csv("ecommerce_orders.csv")
payment_counts = df["Payment Method"].value_counts()
fig, ax = plt.subplots(figsize=(7, 5))
ax.bar(
payment_counts.index,
payment_counts.values,
color=["royalblue", "darkorange", "forestgreen"]
)
ax.tick_params(axis="x", labelrotation=45)
ax.set_title("Order Distribution by Payment Method")
ax.set_xlabel("Payment Method")
ax.set_ylabel("Number of Orders")
plt.tight_layout()
fig.savefig("payment_methods_bar.png", dpi=300)
plt.show()
45° rotation keeps long labels like "Cash on Delivery" readable.
5. Method Summary
| Task | API | Benefit |
| Tick intervals | ax.set_xticks(range(...)) | Explicit scale |
| Rotate labels | ax.tick_params(axis="x", labelrotation=angle) | Avoid overlap |
| Legend location | ax.legend(loc="upper right") | Clear of data |
| Export | fig.savefig(..., dpi=300) | Sharp print files |