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

Posted dushuhubian

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了matplotlib----初探------3散点图相关的知识,希望对你有一定的参考价值。

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

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

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

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

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散点图的主要内容,如果未能解决你的问题,请参考以下文章

matplotlib怎么画三维散点图

python3绘图示例4(基于matplotlib:箱线图散点图等)

matplotlib两种画散点图的方式

Matplotlib绘制散点图与条形图

Matplotlib基础图形之散点图

matplotlib绘制三维散点图示例