gpt4 book ai didi

python - 仅左轴上的网格线

转载 作者:行者123 更新时间:2023-11-30 23:38:39 25 4
gpt4 key购买 nike

import pylab
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker

pyplotParams = {
'backend': 'eps',
'axes.labelsize': 8,
'axes.facecolor': '#E5E5E5', # axes background color
'axes.edgecolor': 'k', # axes edge color
'axes.grid': True, # display grid or not
'axes.axisbelow': True, # show grid below plot elements
'grid.color': 'w', # grid color
'grid.linestyle': '-', # grid line style
'figure.dpi': 80,
'figure.facecolor': 'w',
}

rcParams.update(pyplotParams)
fig1 = plt.figure()
ax4 = fig1.add_subplot(111)
ax4.plot(xaxis3_val,cum_ar_250_ret,color='g')
ax4.plot(xaxis3_val,cum_basket_250_ret,color='b')
ax5 = ax4.twinx()
ax5.plot(xaxis3_val,signal,color='r')
plt.show()

上面的例子是一组 4 个图的简化版本,我想要所有四个地 block 上的网格线。然而在图4中,我只想要网格ax4 而不是 ax5。 Axes 对象(ax5)似乎没有一个简单的方法来设置要关闭的网格打印。如何有选择地关闭 ax5 的网格线?我尝试了以下方法但它不起作用:

(Pdb) ax5.get_xgridlines()
<a list of 6 Line2D xgridline objects>
(Pdb) ax5.grid(ls=None)
*** AttributeError: 'NoneType' object has no attribute 'startswith'
(Pdb)

最佳答案

我认为你只需要关闭网格即可。 (doc)

ax5.grid(False)

关于python - 仅左轴上的网格线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14326338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com