Python之Matplotlib(2)


子图   在matplotlib中整个图像为Figure对象
#在Figure对象中可以包含多个Axes对象
#每一个Axes(ax)对象都是拥有一个自己的坐标系统的绘图区域
#子图   在matplotlib中整个图像为Figure对象
#在Figure对象中可以包含多个Axes对象
#每一个Axes(ax)对象都是拥有一个自己的坐标系统的绘图区域
In [2]:

 inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
In [10]:

fig = plt.figure(figsize=(10,6),facecolor='gray')
fig = plt.figure(figsize=(10,6),facecolor='gray')
ax1 = fig.add_subplot(2,2,1) #第一行的左图
#先创建图表,然后生成子图
plt.plot(np.random.rand(50).cumsum(),'k--')
plt.plot(np.random.randn(50).cumsum(),'g--')
​
ax2 = fig.add_subplot(2,2,2)
ax2.hist(np.random.rand(50))
​
ax3 = fig.add_subplot(2,2,3)
x = np.random.rand(1000)
y = np.random.rand(1000)
ax3.scatter(x,y)
​
ax4 = fig.add_subplot(2,2,4)
df = pd.DataFrame(np.random.rand(10,4),columns=['a','b','c','d'])
ax4.plot(df)
Out[10]:
[<matplotlib.lines.Line2D at 0x12b5c0b8>,
 <matplotlib.lines.Line2D at 0x12b5c320>,
 <matplotlib.lines.Line2D at 0x12b5c518>,
 <matplotlib.lines.Line2D at 0x12b5c710>]
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
#图标的样式参数
#lifestyle - -- -. : 
plt.plot([i**2 for i in range(-100,100)],
        linestyle = ':'
        )
Out[31]:
[<matplotlib.lines.Line2D at 0x13537d68>]

In [32]:

#直方图
df = pd.DataFrame(np.random.randn(1000))
df.hist()
Out[32]:
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x0000000013465240>]],
      dtype=object)

In [33]:

-
df = pd.DataFrame(np.random.randn(1000))
df.plot(kind='kde',linestyle='--')
Out[33]:
<matplotlib.axes._subplots.AxesSubplot at 0x13510198>

In [44]:

s = pd.Series(np.random.randn(100))
s.plot(linestyle='--',
      linewidth=0.5,
     marker = '1',
      figsize=(12,3))
Out[44]:
<matplotlib.axes._subplots.AxesSubplot at 0x150dc160>

In [49]:

2
#透明度
x = np.random.randn(10000)
y = np.random.randn(10000)
plt.scatter(x,y,marker='.',s = 10,alpha=0.2)
Out[49]:
<matplotlib.collections.PathCollection at 0x153967f0>

In [51]:

#整体风格样式
import matplotlib.style as psl
print(plt.style.available)
psl.use('ggplot')
['seaborn-colorblind', 'dark_background', 'bmh', 'seaborn-pastel', 'seaborn-dark', 'seaborn-bright', 'classic', 'seaborn-muted', 'fivethirtyeight', 'ggplot', 'seaborn-deep', 'seaborn-notebook', 'seaborn-dark-palette', 'seaborn-darkgrid', 'seaborn-talk', 'seaborn-whitegrid', 'seaborn-white', 'grayscale', 'seaborn-paper', 'seaborn-ticks', 'seaborn-poster']

猜你喜欢

转载自blog.csdn.net/weixin_38452632/article/details/83714510