Matplotlib Function Points graph for learning matplotlib

Source: Internet
Author: User

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 ()

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.