AttributeError:“ str”对象没有属性“ values”

Slartibartfast

我有以下代码:来源:Matplotlib重叠的注释/文本

import matplotlib.pyplot as plt
from adjustText import adjust_text
import numpy as np
together = [(0, 1.0, 0.4), (25, 1.0127692669427917, 0.41), (50, 1.016404709797609, 0.41), (75, 1.1043426359673716, 0.42), (100, 1.1610446924342996, 0.44), (125, 1.1685687930691457, 0.43), (150, 1.3486407784550272, 0.45), (250, 1.4013999168008104, 0.45)]
together.sort()

text = [x for (x,y,z) in together]
eucs = [y for (x,y,z) in together]
covers = [z for (x,y,z) in together]

p1 = plt.plot(eucs,covers,color="black", alpha=0.5)
texts = []
for x, y, s in zip(eucs, covers, text):
    texts.append(plt.text(x, y, s))

plt.xlabel("Proportional Euclidean Distance")
plt.ylabel("Percentage Timewindows Attended")
plt.title("Test plot")
adjust_text(texts, only_move='y', arrowprops=dict(arrowstyle="->", color='r', lw=0.5))
plt.show()

它确实绘图,但我不断收到此错误:

AttributeError: 'str' object has no attribute 'values'

您能否告知我为什么会收到此错误?

完整错误回溯:

runfile('C:/Users//untitled3.py', wdir='C:/Users/')
Traceback (most recent call last):

  File "C:\Users\\untitled3.py", line 27, in <module>
    adjust_text(texts, only_move='y', arrowprops=dict(arrowstyle="->", color='r', lw=0.5))

  File "C:\Users\\anaconda3\lib\site-packages\adjustText\__init__.py", line 439, in adjust_text
    if not any(list(map(lambda val: 'x' in val, only_move.values()))):

AttributeError: 'str' object has no attribute 'values'
阿帕那

出现此错误的原因是,您提供的only_move是字符串,但是需要字典。在错误屏幕截图的最后一行,您可以看到only_move.values(),错误从此处弹出。PFB示例:

adjust_text(texts, x, y, arrowprops=dict(arrowstyle="->", color='r', lw=0.5),
        autoalign='', only_move={'points':'y', 'text':'y'})

供您参考:https : //adjusttext.readthedocs.io/en/latest/Examples.html

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章