using PyPlot vs using Plots pyplot()

一开始以为using PyPlot, 和 using Plots;pyplot() 是等价的。
但是我操作发现这里边的语法 差别比较大

using PyPlot

x = range(0; stop=2*pi, length=1000); y = sin.(3 * x + 4 * cos.(2 * x));
PyPlot.plot(x, y, color="red", linewidth=2.0, linestyle="--")
PyPlot.title("A sinusoidally modulated sinusoid")
PyPlot.grid("true")  # http://docs.juliaplots.org/latest/generated/attributes_axis/
using Plots
pyplot()
x = range(0; stop=2*pi, length=1000); y = sin.(3 * x + 4 * cos.(2 * x));
plot(x, y, color="red", linewidth=2.0, linestyle= :auto, title="test")

像title这个属性,在PyPlot.plot 的时候 是不能用的。
可能PyPlot.plot更接近matplotlib.pyplot的语法?

Plots定义了一个统一的绘图语法,但具体的绘图操作会交给各个绘图库(PyPlot, GR, Cairo, UnicodePlots) 等等

各个绘图库本身也是能够正常工作的,如果是封装的话,大概率会沿用之前的语法,所以PyPlot和matplotlib.pyplot会比较接近

看了下github介绍,直接using PyPlot确实是调用的matplotlib.pyplot的API

Once Matplotlib and PyPlot are installed, and you are using a graphics-capable Julia environment such as IJulia, you can simply type using PyPlot and begin calling functions in the matplotlib.pyplot API.

1 个赞