Dimas Mukhlas Widiantoro

Welcome To dimasmukhlas.com

I am Dimas Mukhlas Widiantoro, a seasoned growth expert with 12 years of experience growing Brainly. I share my expertise in growth strategies, user acquisition, and product development. View my complete portfolio at codify.my.id

Why using alpha in drawing mathpotlib

 Ah! That alpha parameter is a transparency setting in your scatter plot. Let me break it down:


Code context

housing = strat_train_set.copy()
housing.plot(kind="scatter", x="longitude", y="latitude", alpha=0.1)
plt.show()

  • kind="scatter" → Makes a scatter plot

  • x="longitude", y="latitude" → Plots longitude on the x-axis, latitude on the y-axis

  • alpha=0.1 → Sets transparency of the points


What alpha does

  • Range: 0 (fully transparent) → 1 (fully opaque)

  • Purpose:

    • When you have lots of overlapping points, fully opaque points can hide density patterns.

    • A low alpha (like 0.1) makes points semi-transparent.

    • You can see areas with more overlapping points as darker regions.


Think of it like looking through a foggy layer of dots—more dots in the same spot = darker, clearer density visualization.


Example:

  • alpha=1 → Every dot is solid → overlapping dots hide each other

  • alpha=0.1 → Dots are see-through → you can see clusters more clearly


In your case, since housing likely has thousands of locations, alpha=0.1 helps reveal population density patterns across longitude/latitude.


Post a Comment

0 Comments