Python+matplotlib绘制不同大小和颜色散点图实例

作者:mengwei 时间:2021-12-02 08:50:32 

 具有不同标记颜色和大小的散点图演示。

演示结果:

Python+matplotlib绘制不同大小和颜色散点图实例

实现代码:


import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook

# Load a numpy record array from yahoo csv data with fields date, open, close,
# volume, adj_close from the mpl-data/example directory. The record array
# stores the date as an np.datetime64 with a day unit ('D') in the date column.
with cbook.get_sample_data('goog.npz') as datafile:
 price_data = np.load(datafile)['price_data'].view(np.recarray)
price_data = price_data[-250:] # get the most recent 250 trading days

delta1 = np.diff(price_data.adj_close) / price_data.adj_close[:-1]

# Marker size in units of points^2
volume = (15 * price_data.volume[:-2] / price_data.volume[0])**2
close = 0.003 * price_data.close[:-2] / 0.003 * price_data.open[:-2]

fig, ax = plt.subplots()
ax.scatter(delta1[:-1], delta1[1:], c=close, s=volume, alpha=0.5)

ax.set_xlabel(r'$\Delta_i$', fontsize=15)
ax.set_ylabel(r'$\Delta_{i+1}$', fontsize=15)
ax.set_title('Volume and percent change')

ax.grid(True)
fig.tight_layout()

plt.show()

来源:https://matplotlib.org/index.html

标签:python,matplotlib,散点图
0
投稿

猜你喜欢

  • TensorFlow的reshape操作 tf.reshape的实现

    2022-03-31 01:14:13
  • Python中Selenium上传文件的几种方式

    2022-08-13 04:10:40
  • python 三种方法提取pdf中的图片

    2023-09-18 08:25:58
  • ASP中页面限权访问的几种方法

    2007-12-13 06:53:00
  • PyTorch如何创建自己的数据集

    2022-10-17 05:22:17
  • 基于Python的图像数据增强Data Augmentation解析

    2022-12-21 11:50:31
  • 设置mysql最大连接数的方法

    2010-12-03 16:00:00
  • Python模块pexpect安装及使用流程

    2023-04-19 05:41:29
  • seaborn绘制双变量联合分布图示例详解

    2021-04-29 01:49:24
  • 浅析JavaScript对象转换成原始值

    2023-08-05 02:09:11
  • 使用Python完成15位18位身份证的互转功能

    2021-11-30 03:04:30
  • Python列表list的详细用法介绍

    2021-04-17 06:56:15
  • 各浏览器 CSS Hack 整理

    2008-01-17 10:54:00
  • python如何提取xml指定内容

    2021-07-02 01:21:10
  • python Airtest自动化测试工具的的使用

    2023-10-28 02:12:57
  • 快速掌握 Mysql数据库对文件操作的封装

    2009-02-23 17:37:00
  • 浏览器针对单服务器连接数问题

    2008-05-12 22:27:00
  • 用Dreamweaver MX制作导航下拉菜单

    2009-05-29 18:37:00
  • Python实时监控网站浏览记录实现过程详解

    2021-06-24 23:55:02
  • python多线程使用方法实例详解

    2023-08-18 17:34:00
  • asp之家 网络编程 m.aspxhome.com