【发布时间】:2019-10-06 08:20:35
【问题描述】:
我是 python 和 matplotlib 的新手。 我正在从该站点查看以下给定示例: https://glowingpython.blogspot.com/2012/01/how-to-plot-two-variable-functions-with.html 因为我希望在给定模型的学习率和纪元数的情况下找到最佳准确度。 但是当我稍微玩一下它时,它会缩小到一个小尺寸的图表。 我怎样才能让它保持它的大小? 示例和我的更改如下。
例子:
from numpy import exp, arange
from pylab import meshgrid, cm, imshow, contour, clabel, colorbar, axis, title, show
# the function that I'm going to plot
def z_func(x, y):
return (1 - (x ** 2 + y ** 3)) * exp(-(x ** 2 + y ** 2) / 2)
x = arange(-3.0, 3.0, 0.1)
y = arange(-3.0, 3.0, 0.1)
X, Y = meshgrid(x, y) # grid of point
Z = z_func(X, Y) # evaluation of the function on the grid
im = imshow(Z, cmap=cm.RdBu) # drawing the function
# adding the Contour lines with labels
cset = contour(Z, arange(-1, 1.5, 0.2), linewidths=2, cmap=cm.Set2)
clabel(cset, inline=True, fmt='%1.1f', fontsize=10)
colorbar(im) # adding the colobar on the right
# latex fashion title
title('$z=(1-x^2+y^3) e^{-(x^2+y^2)/2}$')
show()
我的改变:
from numpy import exp, arange
from pylab import meshgrid, cm, imshow, contour, clabel, colorbar, axis, title, show
import random
# the function that I'm going to plot
def z_func(x, y):
return (x * y * random.random())
x = arange(0.001, 1.001, 0.001)
y = arange(1.0, 101.0, 1.0)
X, Y = meshgrid(x, y) # grid of point
Z = z_func(X, Y) # evaluation of the function on the grid
im = imshow(Z, cmap=cm.RdBu) # drawing the function
# adding the Contour lines with labels
cset = contour(Z, arange(-1, 1.5, 0.2), linewidths=2, cmap=cm.Set2)
clabel(cset, inline=True, fmt='%1.1f', fontsize=10)
colorbar(im) # adding the colobar on the right
# latex fashion title
title('title')
show()
【问题讨论】:
标签: python-3.x matplotlib 3d