Julia 使用 PyPlot库 画图

引入PyPlot

简单图 展示

点图,线图,虚线图

>>>plot([1,2,3],"bo--",label="line_1"); #蓝色圆点虚线bo--
>>>legend()  #显示lable
 show()  #非交互式环境,显示图片命令

>>> plot([1,2,3]) #默认是直线图:"b-" >>> plot([1,2,3,4,5,6],"ko")

条形图

>>> bar([1,2,3],[2,4,3])

横向条形图

>>> barh(["one","htisd","nato","kaici","puto"],[1,4,5,2,8])

子图:一行两列

>>> subplot(121);plot([1,2,3]);subplot(122);plot([3,5,2,4])

极坐标图

>>>polar([1,2,3,4,5,6,7,8,9,8]) >>>polar(rand(UInt32,7),"bo--");title("7 point polar graph")

矩阵图

>>> matshow([[1,2],[3,4]]);title(L"this is $\frac{1}{3}$") #添加标题

饼图

>>> pie([20,30,50],labels=["julia","python3","C++"]) >>> pie([20,30,50],labels=["julia","python3","C++"],explode=[0.1,0.1,0.1])

stack_plot

>>>stackplot([i for i=1:30],rand(UInt,30),rand(UInt,30),labels=["cpu1","cpu2"]);legend()

2x2 的子图

>>> data=randn(100)
>>>fig, axs = plt.subplots(2, 2, figsize=(5, 5));
axs[1,1].hist(data);
axs[1, 2].scatter(data, data);
axs[2, 1].plot(data, data);
axs[2,2].hist2d(data, data)
# suptitle("主标题")

条形码???

>>> eventplot(rand(5,10)) >>> eventplot(rand(3,5))

直方图

>>>hist(rand(100))

二维直方图

>>>hist2D([1,2,3,4],[1,3,2,1])

stem 茎图

>>>stem(rand(10))

spy() #展示稀疏模式

step()

二维散点图和三围散点图

>>> scatter([i for i=1:100],randn(100));xlabel("x-show");ylabel("Y-show")
>>>scatter3D(rand(100),rand(100),rand(100))

保存图片命令

3D图形

三维平面

>>>surf(rand(3,4))

折线

>>> mesh(rand(5),rand(5),rand(5,5)) >>> plot3D(rand(10),rand(10),rand(10)) >>> contour3D(rand(10),rand(10),rand(10,10))

>>>asd=[i for i=1:100];plot_surface(asd,asd,asd*asd') >>> plot_wireframe([i for i=1:100],[i for i=1:100],rand(100,100))

存疑?

图片操作

鼠标在图片上停留

其他

使用对象(.)调用

在图中放置文本

改变风格:

import matplotlib.pyplot as plt
print(plt.style.available ) //查看可用的风格
style_one=['grayscale','fivethirtyeight','bmh','dark_background', 
        'seaborn-whitegrid', 'Solarize_Light2','seaborn-notebook',
         'seaborn-paper', 'fast']
for iter in style_one :
    with plt.style.context(iter):
        plt.plot([1,2,3,4,5,6,7,8,5,4,3,9], 'k-o')
        plt.title(iter)
    plt.show()

箭头 解释

plt.annotate('local max', xy=(2, 1), xytext=(3, 1.5),
             arrowprops=dict(facecolor='black', shrink=0.05),
             )

例子

draw() 刷新当前图片

asda=[]
for i=1:100
       push!(asda,i)
       polar(asda)
       draw()  # 要打开交互式环境 ion()
       sleep(1)
end