Python plotting and visualization details, python Visualization

Source: Internet
Author: User

Python plotting and visualization details, python Visualization

Drawing and visualization of Python

1. Enable matplotlib

IPython (IPython -- Pylab) in the most common pylab Mode)

2. The matplotlib image is located in the Figure object.

You can use plt. figure: Create a new Figure. You cannot use an empty Figure to draw a new figure, you must use add_subplot to create one or more subplot axes [0, 1]. You can use sharex and sharey to specify that subplot should have the same X or Y axis.

The padding can be modified using the subplots_adjust method of Figure. wspace and hspace are used to control the percentage of width and height and can be used as the spacing between subplot.

3. Color, label, and line type

  ax.plot(x,y,'g--')

4. Scale labels and Instances

Chart decoration items. Implementation Method: Use the pyplot interface and native matplotlib API that is more object-oriented.

5. Add a legend (legend)

Legend is another important tool used to identify chart elements. The simplest way is to input the label parameter when adding suplot:

  fig = plt.figure();ax = add_subplot(1,1,1)  ax.plot(randn(1000).cumsum(),,'k',label='one')

6. annotation and plotting on Subplot

Annotations can be added using functions such as text, arrow, and annotate.

7. Save the chart to a file

Obtain a PNG image with a minimum white edge and a resolution of DPI.

  plt.savefig('figpath.png',dpi=400,bbox_inches='tight')

Dpi points per inch and bbox_inches can be used to cut the blank area around the current chart.

8. matplotlib Configuration

By using the rc method, plt. rc ('figure ', figsize = (10, 10) Globally default image size is 10X10.

You can also write it as a dictionary:

  font_options = {'family':'monospace','weight':'bold','size':'small'}  plt.rc('font',**font_options)

9. Plotting functions in pandas

Line chart: bar by default; barh histogram and density chart: Series hist method, kin = 'kde' scatter chart: plt. scatter

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

Related Article

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.