鱼C论坛

 找回密码
 立即注册
查看: 5781|回复: 7

[已解决]属性错误module 'matplotlib.pyplot' has no attribute 'hold'

[复制链接]
发表于 2020-8-7 15:49:50 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 idear 于 2020-8-7 16:06 编辑

运行程序的时候出行错误:AttributeError: module 'matplotlib.pyplot' has no attribute 'hold'。应该怎么解决 ,感谢大佬们
最佳答案
2020-8-7 16:52:26
idear 发表于 2020-8-7 16:36
源代码好像使用Python2.7写的

哦哦,新版本中好像弃用了这个hold属性
具体改成什么我还没弄清楚,
你试试 clear() 或者 clf()
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-7 16:15:19 | 显示全部楼层
matplotlib.pyplot好像没有你所用的这个属性‘hold’吧

你的版本是?
代码是什么?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-8-7 16:32:08 | 显示全部楼层
sunrise085 发表于 2020-8-7 16:15
matplotlib.pyplot好像没有你所用的这个属性‘hold’吧

你的版本是?

我用的版本是Python3.8
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-8-7 16:35:40 | 显示全部楼层
idear 发表于 2020-8-7 16:32
我用的版本是Python3.8
  1. ## Plotting the problem
  2.         plt.figure(str(np.random.rand()))
  3.         plt.hold(True)
  4.         plt.grid(True)
  5.         # Plot the circular arc center.
  6.         plt.plot(slipArcSTR['center'][0], slipArcSTR['center'][1], 'kx')
  7.         # Plot the slip circular arc.
  8.         plt.plot(arcPointsCoordsArray[:,0], arcPointsCoordsArray[:,1], 'k-', \
  9.             lw=0.3)
  10.         # Plot the slices.
  11.         for i in range(len(slicesSTRCell)):
  12.             plotslice(slicesSTRCell[i])
  13.         # Plot the material boundary and the slope geometry.
  14.         plt.plot(boundPointsCordsArray[:,0], boundPointsCordsArray[:,1], 'k-')
  15.         # Plot the terrain surface.
  16.         plt.plot(surfaceChordsArray[:,0], surfaceChordsArray[:,1], 'k', lw=2)
  17.         # Plot the water table.
  18.         plt.plot(wtCoordsArray[:,0], wtCoordsArray[:,1], 'b-')
  19.         # Plot the radius of the arc at both ends.
  20.         radius1PlotArray = np.vstack((slipArcSTR['center'], pointAtToeVec))
  21.         plt.plot(radius1PlotArray[:,0], radius1PlotArray[:,1], 'k--', lw=0.5)
  22.         radius2PlotArray = np.vstack((slipArcSTR['center'], pointAtCrownVec))
  23.         plt.plot(radius2PlotArray[:,0], radius2PlotArray[:,1], 'k--', lw=0.5)
  24.         # Plot the factor of safety value in graphic.
  25.         if methodString == 'Allm':
  26.             fsText = ' $f_{\mathrm{s}\, \mathrm{(Fellenius)}}=+\
  27.                 format(selectedFs[0], '.3f')+'\n'+\
  28.                 ' $f_{\mathrm{s}\, \mathrm{(Bishop\, Simp.)}}=+\
  29.                 format(selectedFs[1], '.3f')
  30.         else:
  31.             if methodString == 'Bshp':
  32.                 fsText = ' $f_{\mathrm{s}\, \mathrm{(Bishop\, Simp.)}}=+\
  33.                     str(format(selectedFs, '.3f'))
  34.             else:
  35.                 fsText = ' $f_{\mathrm{s}\, \mathrm{(Fellenius)}}=+\
  36.                     str(format(selectedFs, '.3f'))
  37.         plt.text(0, surfaceChordsArray[0,1], fsText, fontsize = 11, \
  38.             horizontalalignment='left', verticalalignment='bottom')
  39.         ## Final plot details.
  40.         plt.axis('equal')
  41.         plt.xlabel('$x$ distance')
  42.         plt.ylabel('$y$ distance')
  43.         plt.title(projectName)
  44.         plt.hold(False)
  45.         plt.savefig(projectName+outputFormatImg, dpi=300)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-8-7 16:36:38 | 显示全部楼层
sunrise085 发表于 2020-8-7 16:15
matplotlib.pyplot好像没有你所用的这个属性‘hold’吧

你的版本是?

源代码好像使用Python2.7写的
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-7 16:52:26 | 显示全部楼层    本楼为最佳答案   
idear 发表于 2020-8-7 16:36
源代码好像使用Python2.7写的

哦哦,新版本中好像弃用了这个hold属性
具体改成什么我还没弄清楚,
你试试 clear() 或者 clf()
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-8-7 17:00:12 | 显示全部楼层
sunrise085 发表于 2020-8-7 16:52
哦哦,新版本中好像弃用了这个hold属性
具体改成什么我还没弄清楚,
你试试 clear() 或者 clf()

好的好的,我去试试看,谢谢大佬
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-8-7 18:25:57 | 显示全部楼层
sunrise085 发表于 2020-8-7 16:52
哦哦,新版本中好像弃用了这个hold属性
具体改成什么我还没弄清楚,
你试试 clear() 或者 clf()

我刚才把plt.hold()这个属性给删除了,然后程序正常运行了,新版本中好像都是默认使用plt.hold(True)这个值,无需单独调用
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-25 05:53

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表