ValueError: ' upper center ' is not a valid value for loc; supported values are 'best', 'upper right', 'upper left', 'lower left', 'lower right', 'right', 'center left', 'center right', 'lower center', 'upper center', 'center'
//这里原来我以为是upper center的问题,后面看错误提示的时候,将upper center改为center后就解决了错误。但后面发现,出现错误的原因是源代码的upper center的左右两边有空格,删掉就可以了,而不管是错误提示当中的哪一个都可以,区别就是表示框的位置不同。比如
upper right:
upper left:
import tensorflow as tf
import matplotlib.pyplot as plt
x = tf.linspace(-1.0,1.0,500)
target = tf.constant(0.0)
l1_y = tf.abs(target - x)
l2_y = tf.square(target - x)
delta1 = tf.constant(.1)
phuber1_y = tf.multiply(tf.square(delta1),tf.sqrt(1.0 + tf.square((target - x)/delta1))-1.0)
delta2 = tf.constant(3.0)
phuber2_y = tf.multiply(tf.square(delta2), tf.sqrt(1.0 + tf.square((target - x)/delta2))-1.0)
with tf.Session() as sess:
x_array = sess.run(x)
l1_y_output = sess.run(l1_y)
l2_y_output = sess.run(l2_y)
phuber1_y_output = sess.run(phuber1_y)
phuber2_y_output = sess.run(phuber2_y)
plt.plot(x_array, l1_y_output, "g:", label = "L1 Loss")
plt.plot(x_array, l2_y_output, "r-", label = "L2 Loss")
plt.plot(x_array, phuber1_y_output, "k--", label = "P-Huber Loss(1.0)")
plt.plot(x_array, phuber2_y_output,"b-.", label = "P-Huber Loss(5.0)")
# 设置y轴刻度的范围,从0到1
plt.ylim(0, 1)
#设置图例处于图标上部中心位置,字号为11
plt.legend(loc = "center", prop = {"size": 11})
# 输出图形
plt.show()


被折叠的 条评论
为什么被折叠?



