楼主: niuniuyiwan
2557 5

[Stata] [Stata] 如何在Stata图像中添加背景照片 [推广有奖]

  • 7关注
  • 91粉丝

VIP

已卖:1980份资源

学科带头人

91%

还不是VIP/贵宾

-

威望
0
论坛币
14446 个
通用积分
1962.3850
学术水平
1119 点
热心指数
1167 点
信用等级
1061 点
经验
8523 点
帖子
1629
精华
1
在线时间
2492 小时
注册时间
2010-10-10
最后登录
2025-12-19

楼主
niuniuyiwan 在职认证  发表于 2015-9-1 20:40:18 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

如何在Stata图像中添加背景照片

                                注:以下内容转载自:http://www.surveydesign.com.au/tipsgraphs.html               
  1. //在图像中添加背景

  2. //转化地址:  http://www.text-image.com/convert/ascii.html
  3. //set width to 500  转化时特别注意的地方
  4. // 下载后保存到当前工作路径(输入cd/pwd),本例命名为car ascii to text big.txt


  5. set more off
  6. infix str1 a1-a500 1-500 using "car ascii to text big.txt",  clear

  7. //hexdump may be needed to look for unexpected characters
  8. //hexdump "D:\StataMP\ado\personal\data\car ascii to text big.txt", tabulate

  9. //scaling y axis picture data and reversing
  10. generate y=90+((_N-_n+1)*1)

  11. reshape long a, i(y) j(col)

  12. //replacing characters with numbers
  13. replace a="1" if a=="+"
  14. replace a="2" if a=="-"
  15. replace a="3" if a=="."
  16. replace a="4" if a=="/"
  17. replace a="5" if a==":"
  18. replace a="6" if a=="-"
  19. replace a="7" if a=="M"
  20. replace a="8" if a=="N"
  21. replace a="9" if a=="`"
  22. replace a="10" if a=="d"
  23. replace a="11" if a=="h"
  24. replace a="12" if a=="m"
  25. replace a="13" if a=="o"
  26. replace a="14" if a=="s"
  27. replace a="15" if a=="y"

  28. //scaling x axis picture data
  29. replace col=col/10

  30. merge 1:1 _n using  "D:\StataMP\ado\base/a/auto.dta"  //<--------根据需要改变

  31. local size="tiny"

  32. twoway ///
  33. (scatter y col if a=="1" ,msymbol(circle) ///
  34. mcolor("0 0 0*.20") msize(`size') )       ///
  35. (scatter y col if a=="2" ,msymbol(circle) ///
  36. mcolor("255 255 255*.2") msize(`size'))   ///
  37. (scatter y col if a=="3" ,msymbol(circle) ///
  38. mcolor("255 0 0*.2") msize(`size') )      ///
  39. (scatter y col if a=="4" ,msymbol(circle) ///
  40. mcolor("0 0 255*.2") msize(`size') )      ///
  41. (scatter y col if a=="5" ,msymbol(circle) ///
  42. mcolor("0 0 255*.2") msize(`size') )      ///
  43. (scatter y col if a=="6" ,msymbol(circle) ///
  44. mcolor("255 255 0*.2") msize(`size') )    ///
  45. (scatter y col if a=="7" ,msymbol(circle) ///
  46. mcolor("0 255 255*.2") msize(`size') )    ///
  47. (scatter y col if a=="8" ,msymbol(circle) ///
  48. mcolor("255 0 255*.2") msize(`size') )    ///
  49. (scatter y col if a=="9" ,msymbol(circle) ///
  50. mcolor(white) msize(`size') )             ///
  51. (scatter y col if a=="10",msymbol(circle) ///
  52. mcolor(orange*.2) msize(`size') )         ///
  53. (scatter y col if a=="11",msymbol(circle) ///
  54. mcolor(brown*.2) msize(`size') )          ///
  55. (scatter y col if a=="12",msymbol(circle) ///
  56. mcolor(sand*.2) msize(`size') )           ///
  57. (scatter y col if a=="13",msymbol(circle) ///
  58. mcolor(black*.2) msize(`size') )          ///
  59. (scatter y col if a=="14",msymbol(circle) ///
  60. mcolor(black*.2) msize(`size') )          ///
  61. (scatter y col if a=="15",msymbol(circle) ///
  62. mcolor(black*.2) msize(`size') )          ///
  63. (scatter  length mpg)                     ///
  64. (lfit  length mpg)                        ///
  65. ,yscale( range(100 250))                  ///
  66. ytitle(Length ins.) xtitle(mpg)           ///
  67. title(Mpg v Length) legend(off)

  68. exit
复制代码
1.将照片上传,图片转化文本网址:  http://www.text-image.com/convert/ascii.html
2.转换设置(参考)如下图:
点击convert--->result窗口复制保存为car ascii to text big.txt---->保存至当前工作路径(命令窗口输入pwd/cd)
3.运行上述代码

   11.PNG

12.jpg

13.png

  1. //下载GIMP软件(与PS类似)


  2. clear all
  3. set more off

  4. program hex

  5.   syntax varname , Newv(name)

  6.     generate `newv'=((strpos("`=c(alpha)'",`varlist')-1)/2)+10
  7.     replace `newv'=real(`varlist') if `newv'==9.5

  8. end

  9. //values that can be changed
  10. local divide=20     //--------->此处调大,可以缩短时间

  11. insheet using "d:\StataMP\ado\personal\data\fastcar.html", clear  //------>根据需要改变

  12. generate row=.
  13. replace row=1 if strpos(v1,"<TR>")  
  14. replace row=sum(row)

  15. keep if strpos(v1, "<TD  BGCOLOR")   //------>此处进行了修改


  16. split v1,p(#)
  17. split v12,p(>)
  18. keep row v121

  19. generate obs=_n

  20. bysort row (obs):gen col=_n

  21. rename v121 hex
  22. generate hex1=substr(hex,1,1)
  23. generate hex1a=substr(hex,2,1)

  24. generate hex2=substr(hex,3,1)
  25. generate hex2a=substr(hex,4,1)

  26. generate hex3=substr(hex,5,1)
  27. generate hex3a=substr(hex,6,1)

  28. hex hex1, newv(dec1)
  29. hex hex1a, newv(dec1a)

  30. hex hex2, newv(dec2)
  31. hex hex2a, newv(dec2a)

  32. hex hex3, newv(dec3)
  33. hex hex3a, newv(dec3a)

  34. generate dec1b=16*dec1+dec1a
  35. generate dec2b=16*dec2+dec2a
  36. generate dec3b=16*dec3+dec3a

  37. keep dec1b dec2b dec3b row col

  38. generate dec1c=floor(dec1b/`divide')*`divide'
  39. generate dec2c=floor(dec2b/`divide')*`divide'
  40. generate dec3c=floor(dec3b/`divide')*`divide'

  41. gen str20 color=char(34)+string(dec1c,"%3.0f")+" "+string(dec2c,"%3.0f") ///
  42. +" "+string(dec3c,"%3.0f")+char(34)

  43. egen group_col=group(color)

  44. compress
  45. save pict_graph, replace

  46. use pict_graph, clear
  47. quiet summarize col

  48. local size="*`=33/`r(max)''"     //marker size, can be adjusted

  49. levelsof color, local(a)

  50. merge 1:1 _n using  "d:\StataMP\ado\base\a\auto.dta"  //-------->根据需要改变
  51. summarize length

  52. gen y=90+(((_N-_n+1)-90))/(_N/r(max))

  53. //scaling x axis picture data
  54. replace col=col/9

  55. local z=1

  56. foreach i of local a {

  57.   if `z'==1 {
  58. local zz =  ///
  59. `"(scatter y col if group_col==`z',msymbol(square) mcolor(`i') msize(`size'))"'

  60.     local z=2
  61.    }
  62.       else {
  63. local zz1 = ///
  64. `"(scatter y col if group_col==`z' ,msymbol(square) mcolor(`i') msize(`size'))"'

  65. local zz "`zz' `zz1'"
  66. local ++z
  67.       }
  68. }

  69. twoway `zz'                                      ///
  70. (scatter  length mpg, mcolor(red) msize(large))  ///
  71. (lfit  length mpg)                               ///
  72. ,yscale( range(100 325))                         ///
  73. ytitle(Length ins.) xtitle(mpg)                  ///
  74. title(Mpg v Length) legend(off)
复制代码
1.下载GIMP,打开照片
2.文件-->Export as-->保存为fastcar.html,导出设置(参考)如下-->将该文件移至当前工作路径(命令窗口输入pwd/cd)
3.运行上述代码

捕获.PNG



44.jpg

Graph.png


Graph1.png



Graph.png


14.jpg


auto.gif



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Stata tata Characters Unexpected Character 照片

已有 1 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
xddlovejiao1314 + 100 + 100 + 5 + 5 + 5 精彩帖子

总评分: 经验 + 100  论坛币 + 100  学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

本帖被以下文库推荐

沙发
chonghuihedong 发表于 2015-9-1 20:50:38
已有 2 人评分经验 论坛币 收起 理由
xddlovejiao1314 + 10 + 2 鼓励积极发帖讨论
niuniuyiwan + 5 精彩帖子

总评分: 经验 + 10  论坛币 + 7   查看全部评分

藤椅
rrjj101022 发表于 2015-9-1 20:52:06
谢谢分享~~~
已有 2 人评分经验 论坛币 收起 理由
xddlovejiao1314 + 10 + 2 鼓励积极发帖讨论
niuniuyiwan + 5 精彩帖子

总评分: 经验 + 10  论坛币 + 7   查看全部评分

板凳
xddlovejiao1314 学生认证  发表于 2015-9-1 21:37:13
好贴,谢谢分享。
已有 1 人评分论坛币 收起 理由
niuniuyiwan + 5 精彩帖子

总评分: 论坛币 + 5   查看全部评分

报纸
niuniuyiwan 在职认证  发表于 2015-9-1 21:40:41
xddlovejiao1314 发表于 2015-9-1 21:37
好贴,谢谢分享。
感谢师兄一路支持。

地板
xddlovejiao1314 学生认证  发表于 2015-9-1 21:42:36
niuniuyiwan 发表于 2015-9-1 21:40
感谢师兄一路支持。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-30 13:45