码迷,mamicode.com
首页 > 其他好文 > 详细

matplotlib----初探------3散点图

时间:2019-01-20 00:08:03      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:Oday   概念   inf   外观   rda   image   pre   关系   技术   

概念>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

散点图显示两组数据的值,每个点的坐标位置由变量的值决定。

由一组不连接的点完成,用于观察两种变量的相关性。
例如身高-体重、温度-纬度、等等。

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

import numpy as np
import matplotlib.pyplot as plt

height = [161,170,182,175,173,165]
weight = [50,58,80,70,69,55]

plt.scatter(height,weight)

plt.show()

 

 

技术分享图片

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

股票前后两天的涨跌关系

import numpy as np
import matplotlib.pyplot as plt

open,close = np.loadtxt("000001.csv",delimiter=",",skiprows=1,usecols=(1,4),unpack= True)
change = close - open
yesterday = change[:-1]
today = change[1:]
plt.scatter(yesterday,today)
plt.show()

技术分享图片

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

图的外观

颜色, c
点大小, s
透明度, alpha
点形状, marker

 plt.scatter(yesterday,today,s = 100,c = "r",marker="<",alpha=0.5)

技术分享图片

 

作业

使用000001.SH数据。
计算最高价和开盘价之差diff。
绘出前后两天diff的散点图,研究是否有相关性。 

import numpy as np
import matplotlib.pyplot as plt

open,high = np.loadtxt("000001.csv",delimiter=",",skiprows=1,usecols=(1,2),unpack= True)
diff = high - open
yesterday = diff[:-1]
today = diff[1:]
# plt.scatter(yesterday,today)
# plt.show()
plt.scatter(yesterday,today,s = 400,c= y,marker="2",alpha= 0.3)
plt.show()

技术分享图片

 

matplotlib----初探------3散点图

标签:Oday   概念   inf   外观   rda   image   pre   关系   技术   

原文地址:https://www.cnblogs.com/dushuhubian/p/10293720.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!