我看到我可以用Python 绘图:
import matplotlib
matplotlib.pyplot.plot(...)
Run Code Online (Sandbox Code Playgroud)
要么:
import pylab
pylab.plot(...)
Run Code Online (Sandbox Code Playgroud)
这两个都使用相同的matplotlib绘图代码.
那么,Python社区推荐哪一种作为更好的绘图方法呢?为什么?
以前,我遇到了多个Matplotlib数字之间干扰的问题.最后,我跟踪了一个问题,即某些pyplot函数没有附加到它们的图形实例,但可以在其他一些并行创建的图形实例中呈现.
这是一些示例代码:
from django.http import HttpResponse
from numpy import arange, meshgrid
from matplotlib.mlab import bivariate_normal
def show_chart(request):
delta = 0.025
x = arange(-3.0, 3.0, delta)
y = arange(-2.0, 2.0, delta)
X, Y = meshgrid(x, y)
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = 10.0 * (Z2 - Z1)
from matplotlib.pyplot import figure, contour
fig1 = figure(figsize=(4, 4), facecolor='white')
contour(X, Y, Z)
response = HttpResponse(content_type='image/png')
fig1.savefig(response, format='png')
fig1.clear()
return …
Run Code Online (Sandbox Code Playgroud)