我觉得我的女神很漂亮,想把她的照片当成图表背景,该怎么做?

我觉得我的女神很漂亮,想把她的照片当成图表背景,该怎么做?

这个绘图方法来自于http://www.surveydesign.com.au/tipsgraphs.html, 该网站上给出了两种方法,经过好几天的尝试发现只有第一种比较好用,我们先来试试第一种。(这是是用纯 Stata 绘制, 实际上使用一些 JavaScript 图表库非常容易绘制)

水彩风格

工具

  • 图片转换网站:http://www.text-image.com/convert/ascii.html
  • 平台:Stata
  • 女神照片一张
  • 绘制图表的数据集一个:系统数据集 auto
  • 思想:把图表上的所有像素点转换成数据值,然后绘制散点图

步骤

  1. 把图片上传到这个网站,注意宽度设置成 500。
  2. 把转换的结果保存为一个 txt 文件,这里我命名为 xiaoxiao.txt
  3. 准备数据集,我们以系统数据集 auto.dta 为例:
  4. 运行下面的代码(注意代码里面的颜色是自己根据图片配出来的,可以使用 RGB 颜色编码):
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
infix strL a1-a500 1-500 using "xiaoxiao.txt", clear
gen y = 90 + ((_N-_n+1)*1)
reshape long a, i(y) j(col)

replace a = "1" if a == "+"
replace a = "2" if a == "-"
replace a = "3" if a == "."
replace a = "4" if a == "/"
replace a = "5" if a == ":"
replace a = "6" if a == "-"
replace a = "7" if a == "M"
replace a = "8" if a == "N"
replace a = "9" if a == "`"
replace a = "10" if a == "d"
replace a = "11" if a == "h"
replace a = "12" if a == "m"
replace a = "13" if a == "o"
replace a = "14" if a == "s"
replace a = "15" if a == "y"

replace col = col/10

merge 1:1 _n using auto.dta
local size = "vtiny"

tw ///
(sc y col if a == "1" ,msymbol(circle) ///
mcolor("0 0 0*.2") msize(`size') ) ///
(sc y col if a == "2" ,msymbol(circle) ///
mcolor("255 255 255*.2") msize(`size')) ///
(sc y col if a == "3" ,msymbol(circle) ///
mcolor("255 0 0*.2") msize(`size') ) ///
(sc y col if a == "4" ,msymbol(circle) ///
mcolor("0 0 255*.2") msize(`size') ) ///
(sc y col if a == "5" ,msymbol(circle) ///
mcolor("0 0 255*.2") msize(`size') ) ///
(sc y col if a == "6" ,msymbol(circle) ///
mcolor("255 255 0*.2") msize(`size') ) ///
(sc y col if a == "7" ,msymbol(circle) ///
mcolor("0 255 255*.2") msize(`size') ) ///
(sc y col if a == "8" ,msymbol(circle) ///
mcolor("255 0 255*.2") msize(`size') ) ///
(sc y col if a == "9" ,msymbol(circle) ///
mcolor(white) msize(`size') ) ///
(sc y col if a == "10",msymbol(circle) ///
mcolor(orange*.2) msize(`size') ) ///
(sc y col if a == "11",msymbol(circle) ///
mcolor(brown*.2) msize(`size') ) ///
(sc y col if a == "12",msymbol(circle) ///
mcolor(sand*.2) msize(`size') ) ///
(sc y col if a == "13",msymbol(circle) ///
mcolor(black*.2) msize(`size') ) ///
(sc y col if a == "14",msymbol(circle) ///
mcolor(black*.2) msize(`size') ) ///
(sc y col if a == "15",msymbol(circle) ///
mcolor(black*.2) msize(`size') ) ///
(sc length mpg, msize(small)) ///
(lfit length mpg) ///
,yscale( range(100 250)) ///
ytitle(长度) xtitle(里程数) legend(off)
  1. 结果:

(配色是自己配的。。。好像还是配的挺乱的。。)

# Stata

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×