错误值错误'转换'必须是' matplotlib.transform.Transform'的一个实例。

时间:2018-03-22 02:00:21

标签: python matplotlib

嗨,不知道这里发生了什么是遵循教程并且在代码中没有sytax错误或警告但是当我运行时我得到了这个。

Traceback (most recent call last):

  File "<ipython-input-7-d2d08b3c451f>", line 1, in <module>
    runfile('C:/FILES1/BIZ/CURRENCIES/PROG/STUFF/testapps/spyder/ProgsForSteve/plottest.py', wdir='C:/FILES1/BIZ/CURRENCIES/PROG/STUFF/testapps/spyder/ProgsForSteve')

  File "C:\Users\anwar\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "C:\Users\anwar\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/FILES1/BIZ/CURRENCIES/PROG/STUFF/testapps/spyder/ProgsForSteve/plottest.py", line 20, in <module>
    plt.plot(x, y, label = label1)

  File "C:\Users\anwar\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 3347, in plot
    ax = gca()

  File "C:\Users\anwar\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 984, in gca
    return gcf().gca(**kwargs)

  File "C:\Users\anwar\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 601, in gcf
    return figure()

  File "C:\Users\anwar\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 548, in figure
    **kwargs)

  File "C:\Users\anwar\Anaconda3\lib\site-packages\matplotlib\backend_bases.py", line 160, in new_figure_manager
    fig = fig_cls(*args, **kwargs)

  File "C:\Users\anwar\Anaconda3\lib\site-packages\matplotlib\figure.py", line 366, in __init__
    self.bbox = TransformedBbox(self.bbox_inches, self.dpi_scale_trans)

  File "C:\Users\anwar\Anaconda3\lib\site-packages\matplotlib\transforms.py", line 1050, in __init__
    raise ValueError("'transform' must be an instance of "

ValueError: 'transform' must be an instance of 'matplotlib.transform.Transform'

这是我的代码

# -*- coding: utf-8 -*-

import matplotlib.pyplot as plt
import datetime as t

incur1 ='nzd'
incur2 = 'usd'
time = t.datetime
first_exRtRate1 = 0.712

label1 = (incur1+ '/' +incur2)
label2 = (incur2+ '/' +incur1)

x = []
y = []
x2 = []
y2 = []
plt.ion()
plt.plot(x, y, label = label1)
plt.plot(x2, y2, label = label2)
plt.xlabel ('Time')
plt.ylabel ('Ex Rate')
plt.title (+incur1+ '/' +incur2+ '/nEx Rate Data')
plt.legend()


time = t.datetime
x.append(time)
y.append(first_exRtRate1) 

plt.show()

我尝试自己另外导入matplotlib以确保matplotlib.transform存在,但这并不好。

我不知道如何解决转换问题,甚至不知道从哪里开始。

我认为这是一个问题,它试图使用变换来创建情节,但它不是从matplotlib获取它应该导入变换或什么?

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,然后我只是重新启动了Spyder,问题就消失了。

另一种可能的解决方法是使用

创建一个新的虚拟环境。
conda create --name myenv

并使用以下命令在新环境中安装spyder

conda install spyder

,然后打开Spyder,转到工具>首选项,然后将Python解释器更改为新环境文件夹中存在的Python.exe文件,然后运行代码。

相关问题