国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Pycharm使用matplotlib報錯:TypeError: vars() argument must have __dict__ attribute 解決方法

這篇具有很好參考價值的文章主要介紹了Pycharm使用matplotlib報錯:TypeError: vars() argument must have __dict__ attribute 解決方法。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

Pycharm使用matplotlib繪圖時報錯


問題描述

TypeError: vars() argument must have __dict__ attribute

源程序:

# -*- encoding: utf-8 -*-
'''
@File    :   MaLearnTest01_1.py
@Time    :   2023/03/03 09:39:05
@Author  :   seveN1foR
@Version :   1.0
@Contact :   sevencdxxiv@qq.com
'''

# here put the import lib

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

def draw(FillStyle):
    x_coords = np.linspace(-100, 100, 500)
    y_coords = np.linspace(-100, 100, 500)
    points = []

    for y in y_coords:
        for x in x_coords:
            if ((x * 0.03) ** 2 + (y * 0.03) ** 2 - 1) ** 3 - (x * 0.03) ** 2 * (y * 0.03) ** 3 <= 0:  # 引用公式
                points.append({"x": x, "y": y})

    heart_x = list(map(lambda point: point["x"], points))
    heart_y = list(map(lambda point: point["y"], points))

    if FillStyle == 1:
        plt.scatter(heart_x, heart_y, s=10, alpha=0.5)
    else:
        plt.scatter(heart_x, heart_y, s=10, alpha=0.5, c=range(len(heart_x)), cmap='autumn')
    plt.show()
    print(mpl.get_backend())


# 主過程
fStyle = 2
draw(fStyle)

運行結果:

Pycharm使用matplotlib報錯:TypeError: vars() argument must have __dict__ attribute 解決方法


原因分析:

在 PyCharm(至少在科學項目中)使用交互式控制臺運行所有文件,其中使用了后端 module://backend_interagg。 這個后端會導致與您相同的錯誤。所以。 在你的文件頭部添加 mpl.use(‘TkAgg’) ,或者檢查你可以使用哪個后端并在此函數(shù)中傳遞這些名稱。


解決方案:

在你的文件頭部添加 mpl.use(‘TkAgg’) ,或者檢查你可以使用哪個后端并在此函數(shù)中傳遞這些名稱。
但是在某些情況下,TkAgg 可能不可用。 第一次檢查時,您使用的是哪個后端。 為此,運行這個簡單的代碼:

import matplotlib as mpl
print(mpl.get_backend())

你必須在 PyCharm 之外的默認終端中手動運行。 (例如創(chuàng)建簡單的 test.py 文件,粘貼代碼,然后運行 python test.py)

頭部添加use后的代碼:

# -*- encoding: utf-8 -*-
'''
@File    :   MaLearnTest01_1.py
@Time    :   2023/03/03 09:39:05
@Author  :   seveN1foR
@Version :   1.0
@Contact :   sevencdxxiv@qq.com
'''

# here put the import lib

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

mpl.use('TkAgg')  # !IMPORTANT 更改在這里?。。。。。。。?!
"""
Why? Because PyCharm (at least in scientific projects) runs all files with an interactive console, 
where backend module://backend_interagg is used. 
And this backend causes the same error as you have.
So. add mpl.use('TkAgg') in head of your file, 
or checkout which backend you can use and past those name in this function.
"""


def draw(FillStyle):
    x_coords = np.linspace(-100, 100, 500)
    y_coords = np.linspace(-100, 100, 500)
    points = []

    for y in y_coords:
        for x in x_coords:
            if ((x * 0.03) ** 2 + (y * 0.03) ** 2 - 1) ** 3 - (x * 0.03) ** 2 * (y * 0.03) ** 3 <= 0:  # 引用公式
                points.append({"x": x, "y": y})

    heart_x = list(map(lambda point: point["x"], points))
    heart_y = list(map(lambda point: point["y"], points))

    if FillStyle == 1:
        plt.scatter(heart_x, heart_y, s=10, alpha=0.5)
    else:
        plt.scatter(heart_x, heart_y, s=10, alpha=0.5, c=range(len(heart_x)), cmap='autumn')
    plt.show()
    print(mpl.get_backend())


# 主過程
fStyle = 2
draw(fStyle)

運行結果:

Pycharm使用matplotlib報錯:TypeError: vars() argument must have __dict__ attribute 解決方法

參考文章源地址:

https://stackoverflow.com/questions/75453995/pandas-plot-vars-argument-must-have-dict-attribute文章來源地址http://www.zghlxwxcb.cn/news/detail-515097.html

到了這里,關于Pycharm使用matplotlib報錯:TypeError: vars() argument must have __dict__ attribute 解決方法的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內(nèi)容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • 【已解決】Flask項目報錯TypeError: tuple indices must be integers or slices, not str

    【已解決】Flask項目報錯TypeError: tuple indices must be integers or slices, not str

    本解決方案適用情境 :在 本地可以正常運行 的flask項目, 放到云服務器報錯 TypeError: tuple indices must be integers or slices, not str,即代碼本身無誤的前提,可能因為環(huán)境差異導致的問題。 報錯代碼 TypeError: tuple indices must be integers or slices, not str 這個錯誤的意思是元組索引必須是整

    2024年02月17日
    瀏覽(30)
  • webdriver報錯:TypeError: __init__() got an unexpected keyword argument ‘executable_path‘已解決

    webdriver報錯:TypeError: init () got an unexpected keyword argument \\\'executable_path’已解決 錯誤段代碼如下: 先說一下我下載的chromedriver版本是122.0.6261.94,chrome的版本是122.0.6261.112 selenium或selenium下的webdriver的庫版本的原因,與chromedriver的版本不匹配。 終端執(zhí)行pip show selenium查看版本。我報

    2024年04月25日
    瀏覽(24)
  • Pytorch報錯TypeError : __init__() takes 1 positional argument but 2 were given 原因及解決方法

    問題 : Pytorch報錯TypeError : __init__() takes 1 positional argument but 2 were given 解決方法 : 在網(wǎng)上搜了下,都是說自己的模型定義錯誤,我看了下,發(fā)現(xiàn)也沒有錯誤,就很懵! 然后看看之前的代碼發(fā)現(xiàn)我沒有實例化?。?! 貼代碼 : 這個模塊沒有毛病。 可總是報錯: __init__() takes

    2024年02月13日
    瀏覽(17)
  • rabbitmq集群搭建報錯:[error] Cookie file /var/lib/rabbitmq/.erlang.cookie must be accessible by owner only

    在創(chuàng)建rabbitmq集群時,需要將當前節(jié)點的.erlang.cookie文件數(shù)據(jù)修改為第一個節(jié)點的.erlang.cookie文件內(nèi)容,這里為了防止手動vim修改導致數(shù)據(jù)末尾的自動換行符的引入,我使用了文件的直接替換,隨后在重啟當前的mq節(jié)點服務時,報錯如下: 結果就是rabbitmq啟動失敗 隨后,執(zhí)行

    2024年02月15日
    瀏覽(26)
  • vue/cli@4執(zhí)行npm run build報錯:Syntax Error: Thread Loader (Worker 2) The “from“ argument must be of

    vue/cli@4執(zhí)行npm run build報錯:Syntax Error: Thread Loader (Worker 2) The “from“ argument must be of

    目錄 1、問題 2、原因 3、解決方案 Syntax Error: Thread Loader (Work 2) The \\\"from\\\" argument must be of type string. Received undefined 語法錯誤:線程加載器(工作2) “from”參數(shù)的類型必須為字符串。接收未定義 錯誤提示代碼: vue-cli?使用 wokrer-loader 加載 web woker 時,使用 npm run build 有很大機

    2024年02月09日
    瀏覽(25)
  • 已解決(selenium操作火狐瀏覽器報錯)TypeError: __init__() got an unexpected keyword argument ‘firefox_options‘

    已解決(selenium操作火狐瀏覽器報錯)TypeError: __init__() got an unexpected keyword argument ‘firefox_options‘

    已解決(selenium操作火狐瀏覽器報錯)TypeError: init () got an unexpected keyword argument ‘firefox_options‘ 粉絲群里面的一個小伙伴想用selenium操作火狐瀏覽器,但是發(fā)生了報錯(當時他心里瞬間涼了一大截,跑來找我求助,然后順利幫助他解決了,順便記錄一下希望可以幫助到更多遇

    2024年02月09日
    瀏覽(27)
  • 【python】pycharm 2023.02導入matplotlib報錯

    換新電腦、重裝系統(tǒng)后,新裝的pycharm 2023.02版本導入 matplotlib 會報錯:找不到指定的模塊 需要重新安裝?Microsoft Visual C++ 2015 Redistributable Update 3或更高版本 下載鏈接:Download Microsoft Visual C++ 2015 Redistributable Update 3 from Official Microsoft Download Center

    2024年02月13日
    瀏覽(22)
  • 【學習】python之使用pandas提示TypeError: NDFrame.to_excel() got an unexpected keyword argument ‘encoding‘

    【學習】python之使用pandas提示TypeError: NDFrame.to_excel() got an unexpected keyword argument ‘encoding‘

    槳槳,終于有東西可以來記錄解決的問題點啦~ 背景是在使用pandas一直無法轉換成excel,排查了很久,終于在做了一個細微的調整實現(xiàn)成功了。 pandas 是基于NumPy 的一種工具。我的理解:這個包可以實現(xiàn)讀取excel,寫入excel的功能,分別是readexcel,toexcel。 運行報錯提示 Traceback (m

    2024年04月08日
    瀏覽(78)
  • PyCharm使用matplotlib:報MatplotlibDeprecationWarning.問題已解決

    PyCharm使用matplotlib:報MatplotlibDeprecationWarning.問題已解決

    這個錯誤全部顯示為:MatplotlibDeprecationWarning: Support for FigureCanvases without a required_interactive_framework attribute was deprecated in Matplotlib 3.6 and will be removed two minor releases later. 報錯截圖如下所示: 代碼示例: import matplotlib.pyplot as plt import numpy as np x = np.arange(0, 10, 0.1) y = np.sin(x) plt.plot

    2024年02月06日
    瀏覽(30)
  • 修復 Python 錯誤TypeError: Missing 1 Required Positional Argument

    類是面向對象編程語言的基本特征之一。 每個對象都屬于 Python 中的某個類。 我們可以創(chuàng)建我們的類作為藍圖來創(chuàng)建相同類型的對象。 我們使用 class 在 Python 中定義一個類。 Python 中一個非常重要的特性是在定義類時使用 self 屬性。 self 屬性表示對象的數(shù)據(jù)并將參數(shù)綁

    2024年02月10日
    瀏覽(21)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包