python_pandas_matplolib绘图(4)

pandas本身自带绘图

线性图

df = pd.DataFrame(np.random.rand(100,4).cumsum(0), columns=['A','B','C','D'])   #4列,100个数据
df.plot()
plt.show()

柱状图

# 10-50之间的数,3*4
df = pd.DataFrame(np.random.randint(10,50,(3,4)),columns=['A','B','C','D'], index=['one','two','three'])
df.plot
.bar()
plt.show()

# 等价于上面
df.plot(
kind='bar')
plt.show()

# stacked 叠加效果
df.plot(kind='bar', stacked=True)
plt.show()

#显示其中一个

df.A.plot.bar()
plt.show()

直方图

df = pd.DataFrame(np.random.randn(100,4),columns=['A','B','C','D'])
df.hist(column='A', figsize=(5,4))
plt.show()

密度图

df.plot.kde()  # 等价于 df.plot(kind =‘kde’)
plt.show()

3D图

from mpl_toolkits.mplot3d import Axes3D
from matplotlib.ticker import LinearLocator, FormatStrFormatter

import numpy as np
from matplotlib import cm

 

fig = plt.figure()
ax = fig.gca(projection='3d')

#make data
x = np.arange(-5, 5, 0.25)
y = np.arange(-5, 5, 0.25)
x, y = np.meshgrid(x, y)
r = np.sqrt(x**2 + y**2)
z = np.sin(r)

# plot the surface
surf = ax.plot_surface(x, y, z, cmap = cm.coolwarm,
                      linewidth=0, antialiased=False)

# customize the z axis
ax.set_zlim(-1.01, 1.01)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))

#add a color bar which maps values to colors.
plt.colorbar(surf, shrink=0.5,aspect=5);

fig.savefig('C:/Users/Administrator/3d.png')
plt.show()

 

python_pandas_matplolib绘图(4)

python_pandas_matplolib绘图(4)