1、简单绘制 sin(x)

import mglearn
import matplotlib.pyplot as plt

mglearn.plots.plot_knn_regression(n_neighbors=2)

plt.show()

python 移动坐标轴到图中央

 

 2、隐藏上边和右边的两条轴线

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-np.pi , np.pi)
y = np.sin(x)

plt.plot(x, y)

ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')


plt.legend(['sin(x)'])

plt.show()

python 移动坐标轴到图中央

 

 3、将坐标轴移至中心

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-np.pi , np.pi)
y = np.sin(x)

plt.plot(x, y)

ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.spines['left'].set_position(('data', 0))
ax.spines['bottom'].set_position(('data', 0))

plt.xlim(-4, 4)
plt.ylim(-1.5, 1.5)

plt.legend(['sin(x)'])

plt.show()

python 移动坐标轴到图中央

 

 

。。。

相关文章:

  • 2021-11-08
  • 2021-06-15
  • 2022-12-23
  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-06
  • 2021-07-22
  • 2022-12-23
  • 2021-06-17
  • 2021-05-22
  • 2022-12-23
  • 2021-11-04
相关资源
相似解决方案