关于PyPlot的安装:建议先装一下Python2.7版本环境,这样会有利于在PyPlot.jl库上顺利的安装,这样会大大提高成功率。另外,如果原先已经装好,但更新有问题,建议先删除原有的库(Pkg.rm),后再重新装。

最近在用PyPlot,所以整理了一些现成的PyPlot画图的资源,做个记号,便于随手使用。

一、画一个立体球
http://stackoverflow.com/questions/34821061/plot-sphere-with-julia-and-pyplot

using PyPlot
n = 100
u = linspace(0,2*π,n);
v = linspace(0,π,n);x = cos(u) * sin(v)';
y = sin(u) * sin(v)';
z = ones(n) * cos(v)';# The rstride and cstride arguments default to 10
surf(x,y,z, rstride=4, cstride=4)


二、画曲/线
画一个日期图,思考:日期的X轴需要重新设置成(2016-05-06格式)?

using PyPlot;
clf();
close();
x = [Date(now()) + Dates.Day(i) for i in collect(1:100)] # 日期图
y = rand(100)
PyPlot.plot(x,y, color="red", linewidth=2.0, linestyle="-") # 日期默认格式  Aug 01 2016

也可以写成:

using PyPlot;
clf();
close();
fig =figure();
ax = fig[:add_subplot](111)  # 或 fig, ax = PyPlot.subplots()
x = [Date(now()) + Dates.Day(i) for i in collect(1:100)] # 日期图
y = rand(100)
ax[:plot](x,y, color="red", linewidth=2.0, linestyle="-")


https://github.com/stevengj/PyPlot.jl

using PyPlot
x = linspace(0,2*pi,1000); y = sin(3*x + 4*cos(2*x));
PyPlot.plot(x, y, color="red", linewidth=2.0, linestyle="--")
title("A sinusoidally modulated sinusoid")


http://stackoverflow.com/questions/22041461/julia-pyplot-from-script-not-interactive

using PyCall
@pyimport matplotlib.pyplot as plt
x = linspace(0,2*pi,1000); y = sin(3*x + 4*cos(2*x));
plt.plot(x, y, color="red", linewidth=2.0, linestyle="--")
plt.title("A sinusoidally modulated sinusoid")
plt.show()

三、散点图

http://stackoverflow.com/questions/35432999/gridlines-in-julia-pyplot

using PyPlotfig=figure(figsize=[6,3])
ax1=subplot(1,1,1) # creates a subplot with just one graphicax1[:xaxis][:set_ticks](collect(1:4))  # configure x ticks from 1 to 4
ax1[:yaxis][:set_ticks](collect(4:7))  # configure y ticks from 4 to 7grid("on")
PyPlot.scatter([1,2,3,4],[4,5,6,7])

using PyPlot
fig=figure("Name")
grid("on")
xticks(1:4)
yticks(4:7)
scatter([1,2,3,4],[4,5,6,7])

带彩色散点图:

using PyPlot
(X1, Y1) = (rand(6), rand(6));
(X2, Y2) = (rand(6), rand(6));
(X3, Y3) = (rand(6), rand(6));fig = figure(figsize=(10,10))
# xlabel("My X Label")  # optional x label
# ylabel("My Y Label")  # optional y label
title("Julia Plots Like a Boss")
R = scatter(X1,Y1,color="red", label = "Red Data", s = 40)
G = scatter(X2,Y2,color="blue", label = "Blue Data", s = 60)
B = scatter(X3,Y3,color="green", label = "Green Data", s = 80)
legend(loc="right")
savefig("/path/to/pca1_2_fam.pdf")  ## optional command to save results.

四、热图

http://stackoverflow.com/questions/33855111/julia-real-time-varying-heatmap-using-pyplot

using PyPlot
PyPlot.ion()
fig = figure()
ax = fig[:add_subplot](111)
img = ax[:imshow](rand(50,50))
#PyPlot.show()# draw some data in loop
for i in 1:10# wait for a secondsleep(1)# replace the image contentsimg[:set_array](rand(50,50))# redraw the figurefig[:canvas][:draw]
end


五、设定Legend的字体

using PyPlot
fig, ax = PyPlot.subplots()
ax[:plot](rand(10), rand(10), label = "Data")
ax[:legend](loc="best", fontsize=20)

@pyimport  matplotlib.pyplot as plt
@pyimport matplotlib.font_manager as fm
prop = fm.FontProperties(size=9)
fig, ax = PyPlot.subplots()
ax[:plot](rand(10), rand(10), label = "Data")
ax[:legend](loc="best", prop=prop)

六、画动画
这个还有点问题,需要进一步修订。
http://stackoverflow.com/questions/35142199/implementing-an-iterator-in-julia-for-an-animation-with-pyplot

using PyCall
using PyPlot
pygui(true)
@pyimport matplotlib.animation as animation
function simData()
    t_max = 10.0
    dt = 0.05
    x = 0.0
    t = -dt    function it()
        while t < t_max
            x = sin(pi * t)
            t = t + dt
            produce(x, t)
        end
    end    Task(it)
endfunction simPoints()
    task = simData()
    function points(frame_number)
        x, t = consume(task)
        line[:set_data](t, x)
        return(line, "")
    end
    points
endfigure =plt.figure()
axis = figure[:add_subplot](111)
line = axis[:plot]([], [], "bo", ms = 10)[1]
axis[:set_ylim](-1, 1)
axis[:set_xlim](0, 10)
ani = animation.FuncAnimation(figure, simPoints(), blit=false, interval=10, frames=200, repeat=false)
plt.show()

七、polar plot

http://stackoverflow.com/questions/29921611/how-to-change-radial-ticks-in-julia-pyplot-polar-plot


using PyPlot ;theta = 0:0.02:1 * pi ;
n = length(theta) ;U = cos( theta ).^2 ;
V = zeros( size(U) ) ;for i = 1:nv = log10( U[i] ) ;if ( v < -50/10 )v = 0 ;elsev = v/5 + 1 ;endV[i] = v ;
endf1 = figure("p2Fig1",figsize=(10,10)) ; # Create a new figure
ax1 = axes( polar="true" ) ; # Create a polar axispl1 = PyPlot.plot( theta, V, linestyle="-", marker="None" ) ;dtheta = 30 ;
ax1[:set_thetagrids]([0:dtheta:360-dtheta]) ;
ax1[:set_theta_zero_location]("E") ;
ax1[:set_yticks]([0.2,0.4,0.6,0.8,1.0])
ax1[:set_yticklabels](["-40dB","-30dB","-20dB","-10dB","0dB"])
f1[:canvas][:draw]() ;


八 、Plot portfolio composition map

http://stackoverflow.com/questions/33135676/plot-portfolio-composition-map-in-julia-or-matlab

using PyPlot
using PyCall@pyimport matplotlib.patches as patch
clf();
close()
N = 10
D = 4weights = Array(Float64, N,D)for i in 1:N
    w = rand(D)
    w = w/sum(w)
    weights[i,:] = w
end
weights = [zeros(Float64, N) weights]
weights = cumsum(weights,2)
returns = sort!([linspace(1,N, N);] + D*randn(N))##########
#  Plot  #
##########
polygons = Array(PyObject, 4)
colors = ["red","blue","green","cyan"]
labels = ["IBM", "Google", "Apple", "Intel"]
fig, ax = subplots()
fig[:set_size_inches](5, 7)
title("Problem 2.5 part 2")
xlabel("Weights")
ylabel("Return (%)")
ax[:set_autoscale_on](false)
ax[:axis]([0,1,minimum(returns),maximum(returns)])for i in 1:(size(weights,2)-1)
    xy=[weights[:,i] returns;
        reverse(weights[:,(i+1)]) reverse(returns)]
    polygons[i] = matplotlib[:patches][:Polygon](xy, true, color=colors[i], label = labels[i])
    ax[:add_artist](polygons[i])
endlegend(polygons, labels, bbox_to_anchor=(1.02, 1), loc=2, borderaxespad=0)show()
# savefig("CompositionMap.png",bbox_inches="tight")

九、多图

using PyPlot;w = 0.9
w2 = 0.4x = 1:3
y1 = [1,2,3]
y2 = [2,2,2]
y3 = [2,3,1]fig = plt[:figure]()
plt[:bar](x.-(w/2), y1, log=true, width=w, color="#BFBFBF", label="y1")
plt[:bar](x.-(w2/2), y2, log=true, width=w2, color="k", label="y2")
plt[:scatter](x, y3, color="orange", edgecolors="k",s=40, label="y3")

Julia: PyPlot的一些用法整理相关推荐

  1. python数据可视化工具 pandas_Pandas数据可视化工具——Seaborn用法整理(下)

    在前一篇文章 Pandas数据可视化工具--Seaborn用法整理(上),我们了解了如何使用这些Seaborn代码绘制分布图和分类图.在本文中,我们将继续讨论Seaborn提供的一些其他以绘制不同类型 ...

  2. pandas 作图 统计_Pandas数据可视化工具——Seaborn用法整理(下)

    本科数学,编程几乎零基础(之前只学过matlab)今年年初开始学习Python数据挖掘,找到了一个很好的平台--BigQuant,省去了安装Python和安装各种库的烦恼.我最近在开始了解机器学习,B ...

  3. Google Guava 库用法整理

    http://macrochen.iteye.com/blog/737058 参考: http://codemunchies.com/2009/10/beautiful-code-with-googl ...

  4. 《编码规范和测试方法——C/C++版》作业 ·002——函数返回地址、static关键词用法整理

    文章目录 一.函数返回地址的情形 1.函数返回值为指针 二.static关键字用法整理 1.static全局变量 2.static局部变量 3.static函数 4.类的static成员数据 5.类的 ...

  5. Linux中find用法整理

    一.Linux中find常见用法示例 ·find    path    -option    [    -print ]    [ -exec    -ok    command ]    {} /; ...

  6. bitset 用法整理

    在项目中需要使用到10进制48位的数字按二进制由高到低解释,然后按每一位是0还是1来判断报警或错误状态. 所以,在Linux中的C++下需要用到二进制转换以及按位解析.收集到了一些资料,自己保存一下啊 ...

  7. rand函数用法整理

    rand函数用法整理 一.普通用法 1.1 生成随机数 rand()函数不需要参数,它将会返回0到RAND_MAX之间的任意的整数.如果我们想要生成一个在区间[0, 1]之内的数,那么我们可以写出如下 ...

  8. python Faker 包常用法整理

    关于python Faker包用法整理 基本用法 from faker import Faker # 导入第三方包 fake = Faker("zh_CN") # 实例化方法,这是 ...

  9. Displaytag用法整理

    Displaytag用法整理一 1. Displaytag提供的默认的系统提示均为英文,有两种方法进行汉化: 1).将displaytag-1.1.1.jar中自带的org/display/prope ...

  10. maya 常用命令用法整理

    MAYA常用命令用法整理 孤立模式 Shift + i -- 单独显示物体 Ctrl + h -- 隐藏该物体 Ctrl + Shift + h -- 显示上一个被隐藏的物体 /在Outliner / ...

最新文章

  1. swift - label 的font 设置 文字字体和大小
  2. php大于等于符号怎么打出来_PHP常用的特殊运算符号(连续小于符号,三个小于符号,eot,eod,echo示例,print示例)...
  3. 关于ActionBar的向下兼容
  4. python3入门与进阶笔记_我的Python3萌新入门笔记
  5. Apache Mahout 简介 通过可伸缩、商业友好的机器学习来构建智能应用程序
  6. linux 修改权限 anyone,linux 进程管理工具
  7. Java黑皮书课后题第2章:*2.22(金融应用:货币单位)改写程序清单2-10,解决将double转int可能会造成精度损失问题。以整数值作为输入,其最后两位代表的是美分币值
  8. Mini 容器学习笔记4——组件的生命周期(应用篇)
  9. How does framework interpret $expand=Notes
  10. yii开启gii功能
  11. Android 自定义环形圆形显示统计数据z
  12. Win11系统如何恢复隐藏文件
  13. 套接字TCP控制台程序客户端代码示范
  14. ~~欧几里得算法(附模板题)
  15. [转载] Java异常处理中Try-Catch-Finally中常见的笔试题
  16. 音视频开发之旅(41)-天空盒
  17. android版 暴风影音,Android版暴风影音 掌上的3D影院
  18. python编写翻译器_用Python做一个简单的翻译工具
  19. SSH和SSM对比总结
  20. Hadoop集群之开启kerberos安全认证

热门文章

  1. 【面试题】一个号称BAT算法题
  2. cacti 模版大全
  3. [转贴]Unix-Center.Net需要您的帮助
  4. 网络系统设计的一般步骤
  5. Java-集合第二篇Set集合
  6. Master Reactor Manager Worker TaskWorker(Task)
  7. JAVA基础知识总结2(语法基础)
  8. WordPress Exploit Scanner插件安全绕过漏洞
  9. 10 个基于 JavaScript 的机器学习实例
  10. 扇贝有道180907每日一句