1. 安装PyPlot包
using Pkg
Pkg.add("PyPlot")
2.绘制折线图
usingPyPlot
x=1:50
xlabel("x")
y=rand(50)
ylabel("y")
title("base plot")
grid("on")
plot(x,y)

3.绘制手绘风格的曲线图
x=1:10
xlabel("x")
y=ones(10)
fori=1:1:10
y[i]=-i*i*i
end
ylabel("y")
title("XKCD plot")
xkcd()
plot(x,y)

4.创建条形图
x=[1,2,3,4,5]
y=[1,2,4,8,16]
bar(x,y,color="blue")

5.绘制水平条形图
x=[1,2,3,4,5]
y=[1,2,4,8,16]
barh(x,y,color="green")

6. 绘制饼图
labels=["google";"apple";"MS";"xiaomi"]
colors=["orange";"blue";"red";"green"]
sizes=[200;900;30;1400]
fig=figure("pyplot_piechart",figsize=(10,10))
p=pie(sizes,labels=labels,shadow=true,startangle=90,colors=colors)
title("pie plot")

7.绘制散点图
fig=figure("scatterplot",figsize=(10,10))
x=rand(50)
y=rand(50)
areas=10000*rand(50)
scatter(x,y,s=areas,alpha=0.5)
grid("on")
title("Scatter plot")

8.绘制方块图
x=rand(100)
y=rand(100)
xlabel("x")
ylabel("y")
title("hist2D plot")
hist2D(x,y,bins=10)

网友评论