有没有办法使笛卡尔图中的x = 0和y = 0(纵坐标和横坐标)轴变为粗体?
例如,一个简单的情节是:
x = np.arange(0.01, 5, 0.1)
y = np.log(x)
plt.plot(x,y)
plt.grid()
外观如下:
我可以添加此“ hack”:
x = np.arange(0.01, 5, 0.1)
y = np.log(x)
plt.plot(x,y)
plt.grid()
plt.plot(x,0*x, 'k')
plt.plot(x*0,x, 'k')
plt.plot(x*0,-x, 'k')
然后我得到:
是否有一种方法可以使它变少一点-API还是更复杂的解决方案?
答案 0 :(得分:2)
请参见下面的代码:
fig, ax = plt.subplots(1, 1, figsize=(9, 9))
ax.plot(x, y)
ax.grid(True)
ax.axhline(y=0, lw=5, color='k')
ax.axvline(x=0, lw=5, color='k')
答案 1 :(得分:1)
很好的回答,我想补充一下,如果您愿意的话,也可以在color
和color='k'
关键字中传递axhline
(例如axvline
)以使其保持黑色除了调整lw设置线宽以供选择外,