Python uses matplotlib to fill in the code example of the specified area in the graph, pythonmatplotlib

Source: Internet
Author: User

Python uses matplotlib to fill in the code example of the specified area in the graph, pythonmatplotlib

The code in this article focuses on the usage of the fill_between () function in the Python extension library matplotlib. pyplot.

Import numpy as npimport matplotlib. pyplot as plt # generate simulation data x = np. arange (0.0, 4.0 * np. pi, 0.01) y = np. sin (x) # Draw the sine curve plt. plot (x, y) # Draw the reference horizontal line plt. plot (x. min (), x. max (), (0, 0) # Set the axis label plt. xlabel ('x') plt. ylabel ('y') # Fill in the plt of the specified area. fill_between (x, y, where = (2.3 <x) & (x <4.3) | (x> 10), facecolor = 'purple ') # The plt can be filled multiple times. fill_between (x, y, where = (7 <x) & (x <8), facecolor = 'green') plt. show ()

Demo effect:

Summary

The above is all the content about the sample code of using matplotlib to fill the specified area of the graph in Python. I hope it will be helpful to you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!

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.