Customize Scatter Plot Styles using Matplotlib

Import Modules

import matplotlib.pyplot as plt
% matplotlib inline

Fitbit Activity Data

Below is my Fitbit data of daily step count and daily calories burned over a 15-day period.

calories_burned = [3092, 2754, 2852, 2527, 3199, 2640, 2874, 2649,
                   2525, 2858, 2530, 2535, 2487, 2534, 2668]
steps = [15578, 8769, 14133, 8757, 18045, 9087, 14367, 11326, 6776,
                   14359, 10428, 9296, 8177, 8705, 9426]

Initial Plot with Generic Plot Style Customizations

These initial styles could be applied to any type of plot - whether that be a scatter plot, line plot or a histogram.

plt.figure(figsize=(8, 8))
plt.scatter(steps, calories_burned, c='green')
plt.title("Calories Burned Based on Steps Taken", fontsize=18, y=1.03)
plt.xlabel("Steps Taken Per Day", fontsize=14, labelpad=15)
plt.ylabel("Calories Burned Per Day", fontsize=14, labelpad=15)
plt.tick_params(labelsize=12, pad=6);

png

Adjust the Size of Scatter Points on our Plot

Utilize the s argument in our scatter method and pass in the value 70 to make larger scatter points that are easier to see.

plt.figure(figsize=(8, 8))
plt.scatter(steps, calories_burned, c='green', s=70)
plt.title("Calories Burned Based on Steps Taken", fontsize=18, y=1.03)
plt.xlabel("Steps Taken Per Day", fontsize=14, labelpad=15)
plt.ylabel("Calories Burned Per Day", fontsize=14, labelpad=15)
plt.tick_params(labelsize=12, pad=6);

png

Adjust the Transparency of Points on our Plot

Utilize the alpha argument in our scatter method and pass in a numeric value between 0 and 1.

A value of 0 will make the plots fully transparent and unable to view on a white background. A value of 1 is the default with non-transparent points.

We'll make the scatter points slightly transparent so you more easily see the overlap of points near the bottom left of our plot.

plt.figure(figsize=(8, 8))
plt.scatter(steps, calories_burned, c='green', s=70, alpha=0.35)
plt.title("Calories Burned Based on Steps Taken", fontsize=18, y=1.03)
plt.xlabel("Steps Taken Per Day", fontsize=14, labelpad=15)
plt.ylabel("Calories Burned Per Day", fontsize=14, labelpad=15)
plt.tick_params(labelsize=12, pad=6);

png