Menu

Customizing Charts and Using Multiple Plots

Customizing Charts and Using Multiple Plots

Customization makes charts easier to understand and more suitable for reports, dashboards, and presentations.

Customizing Labels, Colors, and Markers

months = ["Jan", "Feb", "Mar", "Apr", "May"]

revenue = [12000, 15000, 13500, 18000, 22000]

plt.figure(figsize=(8, 4))

plt.plot(

months,

revenue,

color="green",

marker="o",

linestyle="--",

linewidth=2,

label="Revenue"

)

plt.title("Monthly Revenue Trend")

plt.xlabel("Month")

plt.ylabel("Revenue")

plt.legend()

plt.grid(True, alpha=0.3)

plt.tight_layout()

plt.show()

Here, figsize sets the figure dimensions, label defines the legend entry, and tight_layout() helps organize the chart elements.

Creating Multiple Subplots

Subplots allow multiple visualizations to appear within one figure. This is useful when comparing different measures from the same dataset.

fig, axes = plt.subplots(1, 2, figsize=(10, 4))

axes[0].bar(["A", "B", "C"], [100, 150, 120])

axes[0].set_title("Units Sold")

axes[1].plot(["Jan", "Feb", "Mar"], [12000, 15000, 18000], marker="o")

axes[1].set_title("Monthly Revenue")

plt.tight_layout()

plt.show()

The subplots() function returns the figure and axes objects. Each axis can be customized independently.

For larger figures, use a layout that keeps labels readable. Too many subplots can make comparisons difficult.


Python for Data Science

VA

Vishalini A



Learn via Video Course

undefined Logo

NaN hrs



Get in Touch For Details