Import library

import matplotlib.pyplot as plt
import numpy as np

Generate colors based on list

We wanna generate a list of colors automatically based on the elements in some list (the idea from popai),

def get_colors(list_vals, list_colors=["#fb4747", "#315ace", "#b5f6e5", "#FFB347"]):
    dict_colors = polylinear_gradient(list_colors, n=len(list_vals))
    dict_colors_ok = {}
    for i, val in enumerate(list_vals):
        dict_colors_ok[val] = dict_colors['hex'][i]

    return dict_colors_ok

Axes

Axes' options,

# Hide the axis
plt.axis('off')
# and 'on' to display it again
# Set the limit
plt.xlim(0, 3.5)
plt.ylim(0, 3.5)
# Axes' label
plt.xlabel('students', fontsize=14)
plt.ylabel('mark')
# axes' tick size & rotation
plt.xticks(fontsize=14, rotation=90)
plt.yticks(fontsize=14, rotation=90)
# range of ticks
plt.xticks(np.arange(0., 1., step=0.01))
plt.yticks(np.arange(0., 1., step=0.01))

Set equal 2 axes (ref),

matplotlib.axes.Axes.set_aspect('equal')
# get the current axes and apply the function
plt.gca().set_aspect()

Plots

Check the official doc for more information.

# default for all
matplotlib.rcParams['figure.figsize'] = (20,5)
plt.plot(X, y, 'ro') # red and 'o' points
# set figure size
plt.figure(figsize=(20, 5))
plt.figure(figsize=(20, 5), dpi= 60)
# rotate z label
plt.xticks(rotation=90, fontsize=10)
# linestyle and marker
plt.plot(marker='.', ls='') # scatter plot
plt.plot(X, '.', markersize=15, linewidth=2)

Plot directly with dataframe,

👉 Check more in official doc.