plt.figure()

plt.figure()

  • Creates a new figure (a new chart canvas).
  • Use it when
    • start a fresh chart
    • control the size
    • make multiple plots
import matplotlib.pyplot as plt
 
def plot(x, y):
 
    plt.figure()
 
    plt.plot(x, y, marker="o")
    plt.xlim(0, 10)
    plt.xticks(range(0, 11))
 
    plt.xlabel("Seconds (last 10s)")
    plt.ylabel("Total size (bytes)")
    plt.title("S3-object-size-history")
    
    plt.show()
 
def main():
    x = [1, 2, 3]
    y = [4, 5, 6]
    plot(x, y)
 
main()

add axis horizontal lineaxhline

plt.axhline()

sample

import matplotlib.pyplot as plt
 
def plot(x, y, global_max):
 
    plt.figure()
 
    plt.plot(x, y, marker="o")
    plt.axhline(y=global_max, color="red",linestyle="--", label=f"Global max = {global_max}") # axis horizontal line
 
    plt.xlim(0, 10)
    plt.xticks(range(0, 11))
 
    plt.xlabel("Seconds (last 10s)")
    plt.ylabel("Total size (bytes)")
    plt.title("S3-object-size-history")
    
    plt.show()
 
def main():
    x = [1, 2, 3, 6, 8]
    y = [4, 5, 6, 3, 2]
    global_max = 5
    plot(x, y, global_max)
 
main()