matplotlib绘制图表----设置坐标轴刻度显示(二)

导入相关模块

import matplotlib.pyplot as plt
import numpy as np

准备数据

x = np.linspace(0, 50)
y = [i ** 2 for i in x]

plt.figure()
plt.plot(x, y)
plt.show()

修改x轴刻度

new_tick = np.array([i for i in range(21)])
plt.xticks(new_tick)            #带替换的x轴刻度
plt.yticks(np.linspace(0, 400, 9),      #带替换的y轴刻度和展示
           ['level1', 'level2','level3','level4','level5','level6','level7','level8','level9'])

plt.show()

猜你喜欢

转载自blog.csdn.net/Stybill_LV_/article/details/106893684
今日推荐