博客
关于我
python可视化编程--matplotlib(二散点图)
阅读量:635 次
发布时间:2019-03-14

本文共 2043 字,大约阅读时间需要 6 分钟。

1、画单个点

# 散点图plit.scatter(2, 4,marker='o',c='b')plit.title("scatter", fontsize=14)plit.xlabel("x", fontsize=14)plit.ylabel("y", fontsize=14)plit.ticklabel_format(axis='both')plit.show()

marker的类型:

 

颜色参数C的值:

2、自动计算

xV = list(np.arange(1, 5))y = [x ** 2 for x in xV]plit.scatter(xV, y,c=(0, 0.5, 0.3))plit.show()

3、颜色映射

plt.scatter(x,y,c=y,cmap=plt.cm.gist_rainbow,s=20)#cm即colormap,c=y表示颜色随y变化

4、自动保存图表

xV = list(np.arange(1, 500))y = [x ** 2 for x in xV]plit.scatter(xV, y, c=y, cmap=plit.cm.hot, s=10)# plit.show()plit.savefig('aaa.png')  #图表保存,代替show

5、随机漫步

模拟随机

randomMy.py文件:

# 随机漫步from random import choiceclass RandomWalk():    def __init__(self, num_points=50):        self.num_points = num_points        self.x_values = [0]        self.y_values = [0]    def fill_walk(self):        while len(self.x_values) < self.num_points:            x_direction = choice([1, -1])            x_distance = choice([0, 1, 2, 3, 4])            x_step = x_direction * x_distance            y_direction = choice([1, -1])            y_distance = choice([0, 1, 2, 3, 4])            y_step = y_direction * y_distance            if x_step == 0 and y_step == 0:                continue            next_x = self.x_values[-1] + x_step            next_y = self.y_values[-1] + y_step            self.x_values.append(next_x)            self.y_values.append(next_y)

调用文件hello.py

# 随机漫步from randomMy import RandomWalkimport matplotlib.pyplot as plitrwn = RandomWalk()rwn.fill_walk()# plit.scatter(rwn.x_values, rwn.y_values, s=15)  #点图1plit.plot(rwn.x_values) #线图2plit.plot(rwn.y_values)  #线图2plit.show()

         

while True:    rwn = RandomWalk()    rwn.fill_walk()    point_number = list(range(rwn.num_points))    plit.scatter(rwn.x_values, rwn.y_values,c=point_number, cmap=plit.cm.hot, s=15)
plit.scatter(0,0,c='green',edgecolors='none',s=100)   //图二   重新绘制原点、终点    plit.scatter(rwn.x_values[-1],rwn.y_values[-1],c='red',edgecolors='none',s=100) //图二 重新绘制原点、终点        plit.show()    keep_running = input("make anoter walk?(y/n):")

 图一               图二

调整尺寸以适应屏幕

plit.figure(figsize=(10,6))

 

 

你可能感兴趣的文章
mysql:Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘解决方法
查看>>
MYSQL:基础——3N范式的表结构设计
查看>>
MYSQL:基础——触发器
查看>>
Mysql:连接报错“closing inbound before receiving peer‘s close_notify”
查看>>
mysqlbinlog报错unknown variable ‘default-character-set=utf8mb4‘
查看>>
mysqldump 参数--lock-tables浅析
查看>>
mysqldump 导出中文乱码
查看>>
mysqldump 导出数据库中每张表的前n条
查看>>
mysqldump: Got error: 1044: Access denied for user ‘xx’@’xx’ to database ‘xx’ when using LOCK TABLES
查看>>
Mysqldump参数大全(参数来源于mysql5.5.19源码)
查看>>
mysqldump备份时忽略某些表
查看>>
mysqldump实现数据备份及灾难恢复
查看>>
mysqldump数据库备份无法进行操作只能查询 --single-transaction
查看>>
mysqldump的一些用法
查看>>
mysqli
查看>>
MySQLIntegrityConstraintViolationException异常处理
查看>>
mysqlreport分析工具详解
查看>>
MySQLSyntaxErrorException: Unknown error 1146和SQLSyntaxErrorException: Unknown error 1146
查看>>
Mysql_Postgresql中_geometry数据操作_st_astext_GeomFromEWKT函数_在java中转换geometry的16进制数据---PostgreSQL工作笔记007
查看>>
mysql_real_connect 参数注意
查看>>