首页 > 其他 > 详细

matplotlib —— 调整坐标轴

时间:2019-01-06 12:28:54      阅读:208      评论:0      收藏:0      [点我收藏+]
import matplotlib.pyplot as plt
import numpy as np

# 绘制普通图像
x = np.linspace(-1, 1, 50)
y1 = 2 * x + 1
y2 = x**2

plt.figure()
plt.plot(x, y1)
plt.plot(x, y2, color = red, linewidth = 1.0, linestyle = --)

# 设置坐标轴的取值范围
plt.xlim((-1, 1))
plt.ylim((0, 2))

# 设置坐标轴的lable
plt.xlabel(X axis)
plt.ylabel(Y axis)

# 设置x坐标轴刻度, 原来为0.25, 修改后为0.5
plt.xticks(np.linspace(-1, 1, 5))
# 设置y坐标轴刻度及标签, $$是设置字体
plt.yticks([0, 0.5], [$minimum$, normal])

# 获取当前的坐标轴, gca = get current axis
ax = plt.gca()
# 设置右边框和上边框
ax.spines[right].set_color(none)
ax.spines[top].set_color(none)
# 设置x坐标轴为下边框
ax.xaxis.set_ticks_position(bottom)
# 设置y坐标轴为左边框
ax.yaxis.set_ticks_position(left)
# 设置x轴, y周在(0, 0)的位置
ax.spines[bottom].set_position((data, 0))
ax.spines[left].set_position((data, 0))
plt.show()

技术分享图片

 

 

参考:  matplotlib的基本用法(三)——调整坐标轴

 

matplotlib —— 调整坐标轴

原文:https://www.cnblogs.com/nxf-rabbit75/p/10228006.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!