用Python的matplotlib画神经网络图,plot.show()运行后没出现图像也没有报错,代码如下,求解决方案 50
%matplotlibinlineimportmatplotlib.pyplotaspltdefdraw_neural_net(ax,left,right,bottom,...
%matplotlib inlineimport matplotlib.pyplot as pltdef draw_neural_net(ax, left, right, bottom, top, layer_sizes): fig = plt.figure(figsize=(12, 12)) ax = fig.gca() ax.axis('off') draw_neural_net(ax, .1, .9, .1, .9, [4, 7, 2]) n_layers = len(layer_sizes) v_spacing = (top - bottom)/float(max(layer_sizes)) h_spacing = (right - left)/float(len(layer_sizes) - 1) # Nodes for n, layer_size in enumerate(layer_sizes): layer_top = v_spacing*(layer_size - 1)/2. + (top + bottom)/2. for m in xrange(layer_size): circle = plt.Circle((n*h_spacing + left, layer_top - m*v_spacing), v_spacing/4., color='w', ec='k', zorder=4) ax.add_artist(circle) # Edges for n, (layer_size_a, layer_size_b) in enumerate(zip(layer_sizes[:-1], layer_sizes[1:])): layer_top_a = v_spacing*(layer_size_a - 1)/2. + (top + bottom)/2. layer_top_b = v_spacing*(layer_size_b - 1)/2. + (top + bottom)/2. for m in xrange(layer_size_a): for o in xrange(layer_size_b): line = plt.Line2D([n*h_spacing + left, (n + 1)*h_spacing + left], [layer_top_a - m*v_spacing, layer_top_b - o*v_spacing], c='k') ax.add_artist(line)plt.show()
展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询