1. 文件读写
语法和python很像,读文件使用open-readlines-close,写文件使用open-println(file,data)-close
使用DelimitedFiles包中的readlm()读取csv文件。
1.1 读文件
readline读取一行;readlines读取所有行为一个数组;eachline读取为一个迭代器:
1.2 写文件
1.3 json文件
using ProgressMeter
@showprogress 1 "Retrieving Julian info..." for ...
using JSON
# write to file
userdata = Dict("nodes"=>usernodes, "links"=>userlinks)
open("Julians.json", "w") do f
JSON.print(f, userdata, 2)
end
2. 绘图
2.1 pyplot
既然都装了python了,就用pyplot绘图吧。
using PyPlot
x=1:10
xlabel("x")
y=ones(10)
for i=1:10
y[i]=-i*i*i
end
ylabel("y")
title("XKCD plot")
plot(x,y)
另一种方式:
第三种方式:
2.2 使用Images
using Images
url = "..."
download(url,"test.jpg")
load("test.jpg")
下载图片,并绘制原图
2.3 skimage
pyplot()
@pyimport skimage.io as io
io.imshow("test.jpg") # 也可以直接放链接
2.4 Plots
using Plots
import FileIO
pyplot()
plot(FileIO.load("test.jpg"))