欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解pandas.DataFrame.plot() 畫圖函數(shù)

 更新時間:2020年06月14日 16:20:20   作者:brucewong0516  
這篇文章主要介紹了詳解pandas.DataFrame.plot()畫圖函數(shù),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

首先看官網(wǎng)的DataFrame.plot( )函數(shù)

DataFrame.plot(x=None, y=None, kind='line', ax=None, subplots=False, 
        sharex=None, sharey=False, layout=None,figsize=None, 
        use_index=True, title=None, grid=None, legend=True, 
        style=None, logx=False, logy=False, loglog=False, 
        xticks=None, yticks=None, xlim=None, ylim=None, rot=None,
        xerr=None,secondary_y=False, sort_columns=False, **kwds)

參數(shù)詳解如下:

Parameters:
x : label or position, default None#指數(shù)據(jù)框列的標(biāo)簽或位置參數(shù)

y : label or position, default None

kind : str
‘line' : line plot (default)#折線圖
‘bar' : vertical bar plot#條形圖
‘barh' : horizontal bar plot#橫向條形圖
‘hist' : histogram#柱狀圖
‘box' : boxplot#箱線圖
‘kde' : Kernel Density Estimation plot#Kernel 的密度估計圖,主要對柱狀圖添加Kernel 概率密度線
‘density' : same as ‘kde'
‘a(chǎn)rea' : area plot#不了解此圖
‘pie' : pie plot#餅圖
‘scatter' : scatter plot#散點(diǎn)圖 需要傳入columns方向的索引
‘hexbin' : hexbin plot#不了解此圖

ax : matplotlib axes object, default None#**子圖(axes, 也可以理解成坐標(biāo)軸) 要在其上進(jìn)行繪制的matplotlib subplot對象。如果沒有設(shè)置,則使用當(dāng)前matplotlib subplot**其中,變量和函數(shù)通過改變figure和axes中的元素(例如:title,label,點(diǎn)和線等等)一起描述figure和axes,也就是在畫布上繪圖。

subplots : boolean, default False#判斷圖片中是否有子圖
Make separate subplots for each column

sharex : boolean, default True if ax is None else False#如果有子圖,子圖共x軸刻度,標(biāo)簽
In case subplots=True, share x axis and set some x axis labels to invisible; defaults to True if ax is None otherwise False if an ax is passed in; Be aware, that passing in both an ax and sharex=True will alter all x axis labels for all axis in a figure!

sharey : boolean, default False#如果有子圖,子圖共y軸刻度,標(biāo)簽
In case subplots=True, share y axis and set some y axis labels to invisible

layout : tuple (optional)#子圖的行列布局
(rows, columns) for the layout of subplots

figsize : a tuple (width, height) in inches#圖片尺寸大小

use_index : boolean, default True#默認(rèn)用索引做x軸
Use index as ticks for x axis

title : string#圖片的標(biāo)題用字符串
Title to use for the plot

grid : boolean, default None (matlab style default)#圖片是否有網(wǎng)格
Axis grid lines

legend : False/True/'reverse'#子圖的圖例,添加一個subplot圖例(默認(rèn)為True)
Place legend on axis subplots

style : list or dict#對每列折線圖設(shè)置線的類型
matplotlib line style per column

logx : boolean, default False#設(shè)置x軸刻度是否取對數(shù)
Use log scaling on x axis
logy : boolean, default False
Use log scaling on y axis

loglog : boolean, default False#同時設(shè)置x,y軸刻度是否取對數(shù)
Use log scaling on both x and y axes

xticks : sequence#設(shè)置x軸刻度值,序列形式(比如列表)
Values to use for the xticks

yticks : sequence#設(shè)置y軸刻度,序列形式(比如列表)
Values to use for the yticks

xlim : 2-tuple/list#設(shè)置坐標(biāo)軸的范圍,列表或元組形式
ylim : 2-tuple/list

rot : int, default None#設(shè)置軸標(biāo)簽(軸刻度)的顯示旋轉(zhuǎn)度數(shù)
Rotation for ticks (xticks for vertical, yticks for horizontal plots)

fontsize : int, default None#設(shè)置軸刻度的字體大小
Font size for xticks and yticks

colormap : str or matplotlib colormap object, default None#設(shè)置圖的區(qū)域顏色
Colormap to select colors from. If string, load colormap with that name from matplotlib.

colorbar : boolean, optional #圖片柱子
If True, plot colorbar (only relevant for ‘scatter' and ‘hexbin' plots)

position : float  
Specify relative alignments for bar plot layout. From 0 (left/bottom-end) to 1 (right/top-end). Default is 0.5 (center)

layout : tuple (optional) #布局
(rows, columns) for the layout of the plot

table : boolean, Series or DataFrame, default False #如果為正,則選擇DataFrame類型的數(shù)據(jù)并且轉(zhuǎn)換匹配matplotlib的布局。
If True, draw a table using the data in the DataFrame and the data will be transposed to meet matplotlib's default layout. If a Series or DataFrame is passed, use passed data to draw a table.

yerr : DataFrame, Series, array-like, dict and str
See Plotting with Error Bars for detail.

xerr : same types as yerr.

stacked : boolean, default False in line and
bar plots, and True in area plot. If True, create stacked plot.

sort_columns : boolean, default False # 以字母表順序繪制各列,默認(rèn)使用前列順序

secondary_y : boolean or sequence, default False ##設(shè)置第二個y軸(右y軸)
Whether to plot on the secondary y-axis If a list/tuple, which columns to plot on secondary y-axis

mark_right : boolean, default True
When using a secondary_y axis, automatically mark the column labels with “(right)” in the legend

kwds : keywords
Options to pass to matplotlib plotting method

Returns:axes : matplotlib.AxesSubplot or np.array of them

1、畫圖圖形

import pandas as pd 

from pandas import DataFrame,Series

df = pd.DataFrame(np.random.randn(4,4),index = list('ABCD'),columns=list('OPKL'))

df
Out[4]: 
     O     P     K     L
A -1.736654 0.327206 -1.000506 1.235681
B 1.216879 0.506565 0.889197 -1.478165
C 0.091957 -2.677410 -0.973761 0.123733
D -1.114622 -0.600751 -0.159181 1.041668

 

注意一下散點(diǎn)圖scatter是需要傳入兩個Y的columns參數(shù)的:

 

傳入x,y參數(shù)

 

 

同時畫多個子圖,可以設(shè)置 subplot = True

 

2、注意事項(xiàng):

- 在畫圖時,要注意首先定義畫圖的畫布:fig = plt.figure( )
- 然后定義子圖ax ,使用 ax= fig.add_subplot( 行,列,位置標(biāo))
- 當(dāng)上述步驟完成后,可以用 ax.plot()函數(shù)或者 df.plot(ax = ax)
- 在jupternotebook 需要用%定義:%matplotlib notebook;如果是在腳本編譯器上則不用,但是需要一次性按流程把代碼寫完;
- 結(jié)尾時都注意記錄上plt.show()

到此這篇關(guān)于詳解pandas.DataFrame.plot() 畫圖函數(shù)的文章就介紹到這了,更多相關(guān)pandas.DataFrame.plot( )畫圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論