Matplotlib: Use matplotlib to draw charts and matplotlib to draw charts.

Source: Internet
Author: User
Tags api manual

Matplotlib: Use matplotlib to draw charts and matplotlib to draw charts.
Http://blog.csdn.net/pipisorry/article/details/39123171

Matplotlib download and API manual address: http://sourceforge.net/projects/matplotlib/files/matplotlib/

Mathematical library numpy download and API manual address: http://www.scipy.org/Download

Matplotlib official website is: http://matplotlib.org/official website has a wealth of legends and documentation instructions.

Matplotlib address on github: https://github.com/matplotlib


Several plotting examples [From API manual]

1. Simplest diagram:

Code:

#!/usr/bin/env pythonimport matplotlib.pyplot as pltplt.plot([10, 20, 30])plt.xlabel('tiems')plt.ylabel('numbers')plt.show()

Test:

2. pie chart:

Code:

#!/usr/bin/env python# -*- coding: utf-8 -*-from pylab import *# make a square figure and axesfigure(1, figsize=(6,6))ax = axes([0.1, 0.1, 0.8, 0.8])labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'fracs = [15,30,45, 10]explode=(0, 0.05, 0, 0)pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True)title('Raining Hogs and Dogs', bbox={'facecolor':'0.8', 'pad':5})savefig('D:\\pie.png')show()

Test:

 

3. Use the numpy library function:

Code:

#! /Usr/bin/env python #-*-coding: UTF-8-*-import numpy as npimport matplotlib. pyplot as pltt = np. arange (0.0, 1.01, 0.01) s = np. sin (2*2 * np. pi * t) plt. fill (t, s * np. exp (-5 * t), 'R') plt. grid (True) # Save as PDF or PNG or plt. savefig ('d: \ test.pdf ') plt. show ()

Test:

 

From: orders
Python: Use matplotlib to draw charts


How to Use the matplotlib module of python to draw a cumulative distribution chart

The following program draws the cumulative distribution function of random variable X and the cumulative result of array p.
>>> Pl. plot (t, X. cdf (t ))
>>> Pl. plot (t2, np. add. accumulate (p) * (t2 [1]-t2 [0])
 
How can I close the window by using matplotlib in python?

Plt. show () seems to be the only way to do this. It will be executed only when you close it.

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.