import matplotlib.pyplot as plt
fig, (ax1, ax2) = plt.subplots(1, 2, figsize = (20, 10))
ax1.imshow(x, cmap='gray') #0-255级灰度,0为黑色,1为白色
ax1.set_title('images')
ax2.imshow(y, cmap='gray_r') #翻转gray的显示,黑白颠倒
ax2.set_title('masks')
【注意】这个gray_r只对本身是灰度图像才比较明显,如果本身是彩色图像,即使黑白颠倒了也没有太大差别。
import matplotlib.pyplot as plt
x = np.arange(20)
y1 = x
y2 = x**2
y3 = x+2
fig, (ax1, ax2) = plt.subplots(1, 2, figsize = (20, 10))
_ = ax1.plot(x,y1,'b-',x,y2,'r-')
ax1.legend(['x','x**2'])
_ = ax2.plot(x,y3,'b-')
ax2.legend('x+2')
plt.title('func')
plt.show()
参考 https://blog.csdn.net/qq_29721419/article/details/71638912
x = list(range(len(truth_count_list)))
total_width, n = 0.5, 2
width = total_width / n
plt.bar(x, truth_count_list, width=width, label='groundtruth', fc='y') #width表示两个柱形的间隔
for i in range(len(x)):
x[i] = x[i] + width
plt.bar(x, pre_count_list, width=width, label='predict', tick_label=range_list, fc='r')
for x,y1,y2 in zip(x,truth_count_list,pre_count_list): # 在柱状图上显示具体数值
plt.text(x-0.3,y1, '%d' % y1, ha='center', va= 'bottom',fontsize=8)
plt.text(x+0.15,y2, '%d' % y2,ha='center', va= 'bottom',fontsize=8)
plt.legend()
plt.title(r'length of testing set', fontsize=20)
plt.text(5.5,175,r'total of groundtruth:{}'.format(len(length_true)),fontsize=10) #在坐标为(5.5,175)的位置处添加文字
plt.text(5.5,150,r'total of prediction:{}'.format(len(length_pre)),fontsize=10)
plt.savefig('/home/res.jpg')
plt.show()