Python画图练习

import numpy as np
import matplotlib.pyplot as plt
import pylab as pl
%matplotlib inline

'''    #段落注释
plt.figure(1)  #创建图标1
plt.figure(2)   #创建图表2
ax1 = plt.subplot(211)   #在图表2中创建子图1
ax2 = plt.subplot(212)     #在图表2中创建子图2
x = np.linspace(0 , 3 , 100)

for i in range(5):
    plt.figure(1)  #选择图表1
    plt.plot(x , np.exp(i * x/3))
    plt.sca(ax1)  #选择图表2的子图1
    plt.plot(x , np.sin(i*x))
    plt.sca(ax2)
    plt.plot(x , np.cos(i*x))
    
plt.show()

x1 = range(0 , 50)
y1 = [num**2 for num in x1]
x2 = [0,1]
y2 = [0,1]
#pl.plot(x1 , y1)
#pl.plot(x1 , y1 , 'o')   #散点图
pl.plot(x1 , y1 , '--')   #线条样式散点图
pl.show()
Fig = plt.figure(figsize=(8,4))
Ax = Fig.add_subplot(111)
Ax.plot(x1 , y1 , x2 , y2)
Ax2 = Fig.add_subplot(121)
Ax2.plot(x1 ,np.cos(x1))
Fig.show()
Fig.savefig("test.pdf")
'''
 
"""    #段落注释
x = [1, 2, 3, 4, 5]# Make an array of x values
y = [1, 4, 9, 16, 25]# Make an array of y values for each x value
pl.plot(x, y)# use pylab to plot x and y
pl.title('Plot of y vs. x')# give plot a title
pl.xlabel('x axis') #make axis labels
pl.ylabel('y axis')
pl.xlim(0.0, 7.0)# set axis limits
pl.ylim(0.0, 30.)
pl.show()# show the plot on the screen
"""

'''


x1 = [1, 2, 3, 4, 5]# Make x, y arrays for each graph
y1 = [1, 4, 9, 16, 25]
x2 = [1, 2, 4, 6, 8]
y2 = [2, 4, 8, 12, 16]
pl.plot(x1, y1, 'r')# use pylab to plot x and y设置红色
pl.plot(x2, y2, 'g')
pl.title('Plot of y vs. x')# give plot a title
pl.xlabel('x axis')# make axis labels
pl.ylabel('y axis')
pl.xlim(0.0, 9.0)# set axis limits
pl.ylim(0.0, 30.)
pl.show()# show the plot on the screen
'''
'''

#折线图和散点图
x1 = [1, 2, 3, 4, 5]# Make x, y arrays for each graph
y1 = [1, 4, 9, 16, 25]
x2 = [1, 2, 4, 6, 8]
y2 = [2, 4, 8, 12, 16]
p1 ,=pl.plot(x1, y1, 'r')# use pylab to plot x and y设置红色
p2 ,=pl.plot(x2, y2, 'go')
pl.title('Plot of y vs. x')# give plot a title
pl.xlabel('x axis')# make axis labels
pl.ylabel('y axis')
pl.xlim(0.0, 9.0)# set axis limits
pl.ylim(0.0, 30.)
pl.legend([p1 , p2] ,('red line' ,'green circles') , numpoints = 1)                #######
#pl.legend(loc='upper left')
pl.show()# show the plot on the screen
'''
#柱状图
data = np.random.normal(5.0, 3.0, 1000)
# make a histogram of the data array
pl.hist(data)
# make plot labels
#pl.hist(data, histtype='stepfilled')      #没有黑色轮廓
pl.xlabel('data')


pl.show()

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值