<matplotlib.collections.PathCollection at 0x187c22789b0>
fig,axes = plt.subplots(3,3)
axes
<IPython.core.display.Javascript object>
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x00000187C7249B00>,
<matplotlib.axes._subplots.AxesSubplot object at 0x00000187C770BB00>,
<matplotlib.axes._subplots.AxesSubplot object at 0x00000187C773A1D0>],
[<matplotlib.axes._subplots.AxesSubplot object at 0x00000187C775F860>,
<matplotlib.axes._subplots.AxesSubplot object at 0x00000187C7786F28>,
<matplotlib.axes._subplots.AxesSubplot object at 0x00000187C77B65C0>],
[<matplotlib.axes._subplots.AxesSubplot object at 0x00000187C77DEC50>,
<matplotlib.axes._subplots.AxesSubplot object at 0x00000187C780F320>,
<matplotlib.axes._subplots.AxesSubplot object at 0x00000187C78369B0>]],
dtype=object)
#四,散点图#散点图scatter
x =[1,2,3,4,5,6,7,8]
y =[5,2,4,2,1,4,5,2]
plt.scatter(x,y,label='skitscat',color='k',s=25,marker='o')
plt.xlabel('x')
plt.ylabel('y')
plt.title('Interesting Graph\nCheck it out')
plt.legend()
plt.show()
#五,堆叠图#堆叠图stackplot#堆叠图用于显示『部分对整体』随时间的关系
days =[1,2,3,4,5]
sleeping =[7,8,6,11,7]
eating =[2,3,4,3,2]
working =[7,8,7,2,2]
playing =[8,5,7,8,13]
plt.stackplot(days,sleeping,eating,working,playing,colors=['m','c','r','k'])
plt.xlabel('x')
plt.ylabel('y')
plt.title('Interesting Graph\nCheck it out')
plt.show()
#为不同数据添加标签
days =[1,2,3,4,5]
sleeping =[7,8,6,11,7]
eating =[2,3,4,3,2]
working =[7,8,7,2,2]
playing =[8,5,7,8,13]
plt.plot([],[],color='m',label='Sleeping',linewidth=5)
plt.plot([],[],color='c', label='Eating', linewidth=5)
plt.plot([],[],color='r', label='Working', linewidth=5)
plt.plot([],[],color='k', label='Playing', linewidth=5)
plt.stackplot(days,sleeping,eating,working,playing,colors=['m','c','r','k'])
plt.xlabel('x')
plt.ylabel('y')
plt.title('Interesting Graph\nCheck it out')
plt.legend()
plt.show()
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plot
import numpy as np
from matplotlib import style
x = np.linspace(-10,10,101)
y = x
x, y = np.meshgrid(x, y)
z = x **2+ y **2
ax = plot.subplot(111, projection='3d')
ax.plot_wireframe(x, y, z)
plot.show()
t = np.linspace(0, np.pi *2,100)
s = np.linspace(0, np.pi,100)
t, s = np.meshgrid(t, s)
x = np.cos(t)* np.sin(s)
y = np.sin(t)* np.sin(s)
z = np.cos(s)
ax = plot.subplot(111, projection='3d')
ax.plot_wireframe(x, y, z)
plot.show()
#使用pandas和seaborn绘图
#线型图import pandas as pd
s = pd.Series(np.random.randn(10).cumsum(),index=np.arange(0,100,10))
s.plot()#索引为x轴
<matplotlib.axes._subplots.AxesSubplot at 0x1911c648eb8>
df = pd.DataFrame(np.random.rand(10,4).cumsum(0),
columns=['A','B','C','D'],
index = np.arange(0,100,10))
df
A
B
C
D
0
0.597104
0.589393
0.735777
0.767290
10
0.796663
0.869799
1.512095
1.604585
20
1.040885
1.346473
1.774127
2.543832
30
1.362510
1.362242
2.673032
2.946192
40
1.581508
2.174047
3.090430
3.386457
50
2.256305
2.629983
3.372889
4.060371
60
2.385461
3.130221
4.222364
4.311171
70
2.896483
3.595163
4.260149
4.468304
80
3.099516
4.335802
5.207953
5.096282
90
3.680995
4.779841
5.865332
5.155942
df.plot()
<matplotlib.axes._subplots.AxesSubplot at 0x1911dcc1400>
#柱形图
fig,axes = plt.subplots(2,1)
data = pd.Series(np.random.rand(16),index=list('abcdefghijklmnop'))
data.plot.bar(ax=axes[0],color='k',alpha=0.7)#x轴为基准
data.plot.barh(ax=axes[1],color='k',alpha=0.7)#y轴为基准
<matplotlib.axes._subplots.AxesSubplot at 0x1911d7e25c0>
#堆积柱状图
data = pd.DataFrame(np.random.rand(6,4),
index=['one','two','three','four','five','six'],
columns=pd.Index(list('ABCD'),name='Genus'))
data
Genus
A
B
C
D
one
0.594853
0.189521
0.130311
0.998033
two
0.247427
0.221326
0.663043
0.141174
three
0.398459
0.242788
0.112028
0.985286
four
0.365095
0.167354
0.545588
0.185118
five
0.024861
0.389038
0.277269
0.950699
six
0.708134
0.898126
0.259565
0.452563
data.plot.bar()
<matplotlib.axes._subplots.AxesSubplot at 0x1911dcc1b00>
#堆积柱状图
df.plot.barh(stacked=True, alpha=0.5)
<matplotlib.axes._subplots.AxesSubplot at 0x1911def7898>
C:\Anaconda\lib\site-packages\scipy\stats\stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval
<matplotlib.axes._subplots.AxesSubplot at 0x1911ee03be0>
C:\Anaconda\lib\site-packages\scipy\stats\stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval
<matplotlib.axes._subplots.AxesSubplot at 0x1911ee621d0>
#直方图和密度图
tips['tip_pct'].plot.hist(bins=50)
<matplotlib.axes._subplots.AxesSubplot at 0x1911eed9400>
#密度图
tips['tip_pct'].plot.density()
<matplotlib.axes._subplots.AxesSubplot at 0x1912003f748>
C:\Anaconda\lib\site-packages\scipy\stats\stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval
<matplotlib.axes._subplots.AxesSubplot at 0x191202d5710>
sns.regplot('m1','unemp',data=trans_data)
plt.title('changes in log %s versus log %s'%('m1','unemp'))
C:\Anaconda\lib\site-packages\scipy\stats\stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval
Text(0.5,1,'changes in log m1 versus log unemp')
C:\Anaconda\lib\site-packages\scipy\stats\stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval
<seaborn.axisgrid.PairGrid at 0x191203fc2b0>
C:\Anaconda\lib\site-packages\seaborn\categorical.py:3666: UserWarning: The `factorplot` function has been renamed to `catplot`. The original name will be removed in a future release. Please update your code. Note that the default `kind` in `factorplot` (`'point'`) has changed `'strip'` in `catplot`.
warnings.warn(msg)
C:\Anaconda\lib\site-packages\scipy\stats\stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval
<seaborn.axisgrid.FacetGrid at 0x191209ed6d8>
C:\Anaconda\lib\site-packages\seaborn\categorical.py:3666: UserWarning: The `factorplot` function has been renamed to `catplot`. The original name will be removed in a future release. Please update your code. Note that the default `kind` in `factorplot` (`'point'`) has changed `'strip'` in `catplot`.
warnings.warn(msg)
<seaborn.axisgrid.FacetGrid at 0x19120bf3710>