plottest.py-20170920

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 19 00:59:16 2017

@author: vicky
"""

import numpy as np
import cv2
import matplotlib.pyplot as plt
import sys
from matplotlib.animation import FuncAnimation


# # plt.axis([0, 100, 0, 1])
# #plt.ion()
#
# # for i in range(100):
# #     y = np.random.random()
# #     plt.scatter(i,y,'ro')
# #     plt.pause(0.1)
#
# for i in range(100):
#     plt.plot(i, 50, 'ro')
#     plt.axis([0, 30, 0, 45])
#     plt.show()
#     plt.close(0)
#
# plt.close('all')
#
#
# fig.ax = plt.subplots()
# fig.set_tight_layout(True)
#
# #  询问图形在屏幕上的尺寸和DPI(每英寸点数)。
# #  注意当我们把图形储存成一个文件时,我们需要再另外提供一个DPI值
# print('fig size: {0} DPI, size in inches {1}'.format(fig.get_dpi(), fig.get_size_inches()))
#
# # 画出一个维持不变(不会被重画)的散点图和一开始的那条直线。
# x = np.arange(0, 20, 0.1)
# ax.scatter(x, x + np.random.normal(0, 3.0, len(x)))
# line, = ax.plot(x, x - 5, 'r-', linewidth=2)
#
# def update(i):
#    label = 'timestep {0}'.format(i)
#    print(label)
#    # 更新直线和x轴(用一个新的x轴的标签)。
#    # 用元组(Tuple)的形式返回在这一帧要被重新绘图的物体
#    line.set_ydata(x - 5 + i)
#    ax.set_xlabel(label)
#    return line, ax
#
# if __name__ == '__main__':
#    # FuncAnimation 会在每一帧都调用“update” 函数。
#    # 在这里设置一个10帧的动画,每帧之间间隔200毫秒
#    anim = FuncAnimation(fig, update, frames=np.arange(0, 10), interval=200)
#    if len(sys.argv) > 1 and sys.argv[1] == 'save':
#        anim.save('line.gif', dpi=80, writer='imagemagick')
#    else:
#        # plt.show() 会一直循环播放动画
#        plt.show()



# import matplotlib.pyplot as plt
# from matplotlib.patches import Circle
# import numpy as np
# import math
#
# plt.close()  # clf() # 清图  cla() # 清坐标轴 close() # 关窗口
# fig = plt.figure()
# ax = fig.add_subplot(1, 1, 1,xlim=(0, 30), ylim=(0, 45))
# #ax.axis("equal")  # 设置图像显示的时候XY轴比例
# plt.grid(True)  # 添加网格
# plt.ion()  # interactive mode on
# # IniObsX = 0000
# # IniObsY = 4000
# # IniObsAngle = 135
# # IniObsSpeed = 10 * math.sqrt(2)  # 米/秒
#
# for i in range(30):
#     for j in range(45):
#         ax.scatter(i, j, c='b', marker='.')
#         #plt.scatter(i,j, 'ro') # 散点图
#         #ax.scatter.pop(0)  #删除轨迹
#         # 下面的图,两船的距离
#         #plt.show()
#         plt.pause(0.001)


# import numpy as np
# from matplotlib import pyplot as plt
# from matplotlib import animation
#
# # first set up the figure, the axis, and the plot element we want to animate
# fig = plt.figure()
# ax1 = fig.add_subplot(1, 1, 1, xlim=(0, 30), ylim=(0, 45))
# #ax2 = fig.add_subplot(2, 1, 2, xlim=(0, 2), ylim=(-4, 4))
# line, = ax1.plot([], [], 'ro')
# #line2, = ax2.plot([], [], lw=2)
#
#
# def init():
#     line.set_data([], [])
#     #line2.set_data([], [])
#     return line
#
# # animation function.  this is called sequentially
# def animate(i):
#     x =i
#     y =i+10
#     line.set_data(x, y,'ro')
#     return line
#
# anim1 = animation.FuncAnimation(fig, animate, init_func=init, frames=50, interval=10)
# plt.show()


# import numpy as np
# import matplotlib.pyplot as plt
# from matplotlib.animation import FuncAnimation
#
# fig, ax = plt.subplots()
# xdata, ydata = [], []
# ln, = plt.plot([], [], 'ro', animated=True)
#
# def init():
#     ax.set_xlim(0, 30)
#     ax.set_ylim(0, 45)
#     return ln,
#
# def update(frame):
#     #xdata.append(frame)
#     #ydata.append(np.sin(frame))
#     ln.set_data(frame, np.sin(frame))
#     return ln,
#
# ani = FuncAnimation(fig, update, frames=np.linspace(0, 2*np.pi, 128),init_func=init, blit=True)
# plt.show()


# import numpy as np
# import matplotlib.pyplot as plt
# import matplotlib.animation as animation
#
# fig, ax = plt.subplots()
# line, = ax.plot(np.random.rand(10))
# ax.set_ylim(0, 1)
#
#
# def update(data):
#     line.set_ydata(data)
#     return line,
#
#
# def data_gen():
#     while True:
#         yield np.random.rand(10)
#
# ani = animation.FuncAnimation(fig, update, data_gen, interval=100)
# plt.show()

# fig, ax = plt.subplots()
# xdata = [2, 7, 5, 14]
# ydata = [9, 22, 18, 31]
# ln, = plt.plot([], [], 'ro', animated=True)
#
#
# def init():
#     ax.set_xlim(0, 30)
#     ax.set_ylim(0, 45)
#     return ln,
#
#
# def update(frame):
#     # xdata.append(frame)
#     # ydata.append(np.sin(frame))
#     ln.set_data(xdata, ydata)
#     return ln,
#
#
# ani = FuncAnimation(fig, update, frames=[xdata,ydata], init_func=init, blit=True)
# plt.show()
# fig = plt.figure()
# ax = fig.add_subplot(1, 1, 1, xlim=(0, 30), ylim=(0, 45))
# # ax.axis("equal")  # 设置图像显示的时候XY轴比例
# plt.grid(True)  # 添加网格
# plt.plot(ad1, ad2, ad3, ad4)


# fig = plt.figure()
# ax = fig.gca()
# plt.axis([0, 45, 0, 30],'equal')
# ax.set_xticks(np.arange(0, 45, 1))
# ax.set_yticks(np.arange(0, 30, 1))
# plt.scatter(xdata,ydata)
# plt.grid()
# img = plt.gcf()
# plt.show()
#
# img.savefig('/Users/vicky/Desktop/fig.png')

fig = plt.figure()
ax = fig.gca()
plt.axis([0, 56, 0, 56], 'equal')
ax.set_xticks(np.arange(0, 56, 1))
ax.set_yticks(np.arange(0, 56, 1))
xdata=[18,23,13,29]
ydata=[13,26,48,49]
plt.scatter(xdata,ydata,c = ('r','b','g','k'),marker = 'o')
plt.grid()
fig.set_size_inches(18.5, 10.5)
img = plt.gcf()
plt.show()





# plt.scatter(xdata,ydata,c='red')
#
# plt.title('Scatter')
# plt.xlabel('x')
# plt.ylabel('y')
# plt.legend()
# plt.grid(None, 'major', 'both')  # 画出网格背景
# #plt.grid(True)
# plt.show()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值