简单的任务:画一张带权重的散点图。权重用散点的大小来表示。
背景问题产生场景和激发隐藏任务事件/链接/…
画带权重的散点图
环境解决办法适用的环境/版本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30> {screenfetch; conda list numpy; conda list matplotlib}
readlink: illegal option -- f
usage: readlink [-n] [file ...]
:++++. OS: 64bit Mac OS X 10.14.6 18G95
/+++/. Kernel: x86_64 Darwin 18.7.0
.:-::- .+/:-``.::- Uptime: 1d 17h 8m
.:/++++++/::::/++++++/:` Packages: 115
.:///:` Shell: zsh 5.3
` Resolution: 2880x1800
-+++++++++++++++++++++++` DE: Aqua
/++++++++++++++++++++++/ WM: Quartz Compositor
/sssssssssssssssssssssss. WM Theme: Blue
:ssssssssssssssssssssssss- Font: SFMono-Regular
osssssssssssssssssssssssso/` CPU: Intel Core i7-8850H @ 2.60GHz
`syyyyyyyyyyyyyyyyyyyyyyyy+` GPU: Intel UHD Graphics 630 / Radeon Pro 560X
`ossssssssssssssssssssss/ RAM: 9051MiB / 16384MiB
:ooooooooooooooooooo+.
`:+oo+/:-..-:/+o+/-
#
# Name Version Build Channel
numpy 1.16.4 py37hacdab7b_0
numpy-base 1.16.4 py37h6575580_0
#
# Name Version Build Channel
matplotlib 3.1.0 py37h54f8f79_0
问题详细描述问题的范畴/条件/上下文/…
数据的前期处理。
散点图的绘制
细粒度的控制:有些有权重,有些没有。(需要么?存疑)
操作逐步说明用什么工具, 在哪儿, 进行什么操作, 如何检验, 应该获得什么输出 …
这是一个很棒的网站,上面有大多数普通绘图要求的例子。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15"""
Simple demo of a scatter plot.
"""
import numpy as np
import matplotlib.pyplot as plt
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
area = np.pi * (15 * np.random.rand(N))**2 # 0 to 15 point radii
plt.scatter(x, y, s=area, c=colors, alpha=0.5)
plt.show()
重要参数:
s: marker size. 散点图点的大小。和前面的 x/y array 长度一致。
c: colors. 散点的颜色。可以传递一个 color string(eg: ‘#bcbd22’,也可以传递长度和 x/y 相同的一个 array)
如何在实际情况中使用
将数据读入 python 脚本,并转换成 np.array 格式。
然后进行必要的处理,colormap 的决定。
然后绘图。
标题和坐标轴
参考绘图中的代码:
1
2
3
4
5plt.ylabel('Scores')
plt.title('Scores by group and gender')
plt.xticks(ind, ('G1', 'G2', 'G3', 'G4', 'G5'))
plt.yticks(np.arange(0, 81, 10))
plt.legend((p1[0], p2[0]), ('Men', 'Women'))
手册:
title 通过参数可以控制字体,位置和对齐(左中右)。但是一般情况下(参考 gallery 的例子)直接plt.title('My Title')就完事了。
中文问题
Mac 的 matplotlib 在图片中插中文字会变成方块。
目前没什么解法……主要字体问题很麻烦,懒得去弄。
尽量避免吧……
总结再次说明经验应用要注意的, 容易出问题的点, 以及有助记忆的作弊条…
用 scatter 绘图。内置了需要的所有功能。
refer过程中参考过的重要文章/图书/模块/代码/…
永远的: 如何提问
logging:用倒序日期排列来从旧到新记要关键变化
190922 ofey404 init