Python绘制高斯曲线

源码:

 1 import numpy as np
 2 import matplotlib.pyplot as plt
 3 import math
 4 import mpl_toolkits.mplot3d
 5 import tensorflow.compat.v1 as tf
 6 tf.disable_v2_behavior()
 7 
 8 #import tensorflow as tf
 9 from sklearn import datasets
10 
11 sess = tf.InteractiveSession()
12 gamma = tf.constant(-1.0)
13 x, y = np.mgrid[-2:2:0.01, -2:2:0.01]
14 
15 x_data = tf.placeholder(shape=[400, 400], dtype=tf.float32)
16 y_data = tf.placeholder(shape=[400, 400], dtype=tf.float32)
17 
18 Kernel = tf.exp(tf.multiply(gamma, tf.add((x_data*x_data),(y_data*y_data))))
19 Kernel = sess.run(Kernel, feed_dict={x_data: x,y_data: y})
20 
21 ax = plt.subplot(111, projection='3d')
22 ax.plot_surface(x, y, Kernel, rstride=1, cstride=1, cmap='rainbow', alpha=0.9)#绘面
23 ax.set_xlabel('x')
24 ax.set_ylabel('y')
25 ax.set_zlabel('Kernel')
26 plt.show()

 

效果图:

在这里插入图片描述

在这里插入图片描述

posted @ 2021-02-17 12:45  BugMiaowu2021  阅读(443)  评论(0编辑  收藏  举报