Matplotlib Function Points graph for learning matplotlib
# Coding: utf-8import numpy as npfrom matplotlib import pyplot as pltfrom matplotlib. patches import Polygon ''' evaluate function credits ''' def func (x): return-(x-2) * (x-8) + 40 print (plt. style. available) plt. style. use ("ggplot") # plot the curve x = np. linspace (0, 10) y = func (x) fig, ax = plt. subplots () plt. plot (x, y, linewidth = 2) # Set axis a = 2b = 9ax. set_xticks ([a, B]) # sets the abscissa 2, 9ax. set_yticks ([]) # Set the ordinate to null ax. set_xticklabels (['$ a $', '$ B $']) # Set the x-axis to a and bplt. figtext (0.91, 0.09, '$ x $') # Set the axis letter plt. figtext (0.11, 0.88, '$ y $') # determine the polygon ix = np. linspace (a, B) iy = func (ix) ixy = zip (ix, iy) verts = [(a, 0)] + list (ixy) + [(B, 0)] poly = Polygon (verts, facecolor = '0. 9', edgecolor = '0. 5') ax. add_patch (poly) # Add the mathematical formula x_math = (a + B) * 0.5y _ math = 35plt. text (x_math, y_math, R' $ \ int_a ^ B (-(x-2) * (x-8) + 40) $ ', fontsize = 13, horizontalalignment = 'center') plt. title ('functional integration') plt. show ()