程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python data analysis 9 - Matplotlib configuration item

編輯:Python

Catalog

One .Figure Containers and subgraph objects

Figure Containers

Subgraph objects

Subplot

Axes

Draw Double y Axis

Delete a child graph object

Get a child graph object to operate

Two .Axis Container and multi graph layout

Axis Containers

 Axis Introduce

Set up x Axis and y Axis label The location of

Set the scale format on the scale

Set scale object , Scale label object , Calibration line

Multi map layout

Adjust the spacing of subgraphs

Custom layout


One .Figure Containers and subgraph objects

Figure Containers

Matplotlib The drawing is located in the picture (Figure) In the object , We can go through plt.figure() Create a new picture :

from matplotlib import pyplot as plt
fig = plt.figure()

You can use the parameter figsize To set the size scale of the canvas :

example :

Subgraph objects

Subplot

(1)plt.subplot(# Subgraph location   A few lines and columns   Number one )        Create one or more child graph objects ;

(2)fig.add_subplot(# Subgraph location   A few lines and columns   Number one )        The effect is consistent with the above method , The difference is that figure;

example :

When setting the parameters of the subgraph , Besides using set Methods are set together , It can also be set separately :

as follows :

 

Axes

(1)fig.add_axes(# Origin coordinates       Length scale of original drawing )        Use this method to create subgraphs , With the above subplot There is a big difference , As shown below :

example :

In the absence of special requirements , We generally do not use this method to create subgraphs .

Draw Double y Axis

(1)twinx()        Clone a shared x Axis objects ;

example : 

Delete a child graph object

(1)fig.delaxes()

example :

 

Get a child graph object to operate

Use for Loop to fig Of axes Traverse ;

example :

Two .Axis Container and multi graph layout

Axis Containers

 Axis Introduce

Axis It stands for x Axis or y Object of axis . contain Tick( scale ) object ,TickLabel Scale text object , as well as AxisLabel Axis text object .axis Object has some methods to manipulate scales, text, etc .

Set up x Axis and y Axis label The location of

(1)ax1.xaxis.set_label_coords(x,y)

(2)ax1.yaxis.set_label_coords(x,y)

example :

 

Set the scale format on the scale

from matplotlib import ticker
formatter = ticker.FormatStrFormatter(" Custom format ")
ax1.yaxis.set_major_formatter(formatter)

example ( send y The axis scale retains two decimal places ):

 

Set scale object , Scale label object , Calibration line

 

 

Multi map layout

Method :subplots()

import matplotlib.pyplot as plt
fig,axes = plt.subplots(2,2)
axes[0,0].plot([1,2],[1,2])
axes[0,1].plot([1,2],[1,2])
axes[1,0].plot([1,2],[1,2])
axes[1,1].plot([1,2],[1,2])
axes[0,0].set_xlabel("x-label")
axes[0,0].set_ylabel("y-label")
axes[0,0].set_title("title")
axes[0,1].set_xlabel("x-label")
axes[0,1].set_ylabel("y-label")
axes[0,1].set_title("title")
axes[1,0].set_xlabel("x-label")
axes[1,0].set_ylabel("y-label")
axes[1,0].set_title("title")
axes[1,1].set_xlabel("x-label")
axes[1,1].set_ylabel("y-label")
axes[1,1].set_title("title")
plt.show()

example :

 

Adjust the spacing of subgraphs

(1)fig.subplots_adjust(left=None,bottom=None,right=None,top=None,wspace=None,hspace=None)

(2) Use the above method :fig.tight_layout(h_pad=None,w_pad=None)

Custom layout

For complex layouts, you need to use GridSpec object , adopt fig.add_gridspec(2,2) Create fence mode , In the use of fig.add_plot Add subgraph .

When adjusting the sub graph scale :fig.add_gridspec(2,2,width_ratios=width,height_ratios=height)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved