matplotlib中添加元素

1.使用matplotlib在坐标轴中添加文字和折线

代码:

# -*- coding: utf-8 -*-
"""
Created on Wed May 15 16:09:55 2019
@author: mzl
"""
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
# 在图中可以添加基本元素[文字]
# =============================================================================
# plt.figure()
# plt.text( 0.5, 0.5, 'Figure', ha='center',
#           va='center', size=20, alpha=.5 )
# plt.xticks([]), plt.yticks([])
# plt.show()
# =============================================================================


# 在图中可以添加基本元素[文字]
# =============================================================================
from PIL import Image
plt.figure()
plt.xticks([]), plt.yticks([])
im = np.array(Image.open('Houston Rockets.png'))
plt.imshow(im)
plt.show()
# =============================================================================
# 在图中可以添加基本元素「折线」
plt.figure()
plt.plot( [0,1],[0,1] )
plt.show()

结果:

matplotlib中添加元素

matplotlib中添加元素