pycharm matplotlib.pyplot.figure().add_subplot()绘制三维图时报错:ValueError: Unknown projection 3d(bug)
生活随笔
收集整理的這篇文章主要介紹了
pycharm matplotlib.pyplot.figure().add_subplot()绘制三维图时报错:ValueError: Unknown projection 3d(bug)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
報錯描述
出于安全考慮,CSDN不讓文章標題使用英文單引號
ValueError: Unknown projection '3d' # -*- coding: utf-8 -*- """ @File : 1.py @Time : 2020/5/25 21:33 @Author : Dontla @Email : sxana@qq.com @Software: PyCharm """ # 第一種創建3D圖形的方法:創建子圖# 用創建子圖的方法畫出來感覺要比下面的方法小一點??from matplotlib import pyplot as plt # 用來繪制圖形import numpy as np # 用來處理數據fig = plt.figure()print('fig的類型:', type(fig), '\n')print('fig:\n', fig, '\n')ax = fig.add_subplot(111, projection='3d')print('ax的類型:', type(ax), '\n')print('ax:\n', ax, '\n')X = np.arange(-10, 10, 0.25)Y = np.arange(-10, 10, 0.25)X, Y = np.meshgrid(X, Y)Z = 3 * X ** 2 + 2 * Y ** 2 + 5ax.plot_surface(X, Y, Z, cmap='rainbow')plt.show() D:\20200228_play_with_pytorch\python\python.exe C:/Users/SIQI/Desktop/繪制神經網絡輸出函數圖像/1.py Traceback (most recent call last):File "D:\20200228_play_with_pytorch\python\lib\site-packages\matplotlib\projections\__init__.py", line 58, in get_projection_classreturn projection_registry.get_projection_class(projection)File "D:\20200228_play_with_pytorch\python\lib\site-packages\matplotlib\projections\__init__.py", line 25, in get_projection_classreturn self._all_projection_types[name] KeyError: '3d'During handling of the above exception, another exception occurred:Traceback (most recent call last):File "C:/Users/SIQI/Desktop/繪制神經網絡輸出函數圖像/1.py", line 23, in <module>ax = fig.add_subplot(111, projection='3d')File "D:\20200228_play_with_pytorch\python\lib\site-packages\matplotlib\figure.py", line 1396, in add_subplotself._process_projection_requirements(*args, **kwargs)File "D:\20200228_play_with_pytorch\python\lib\site-packages\matplotlib\figure.py", line 1120, in _process_projection_requirementsprojection_class = projections.get_projection_class(projection)File "D:\20200228_play_with_pytorch\python\lib\site-packages\matplotlib\projections\__init__.py", line 60, in get_projection_classraise ValueError("Unknown projection %r" % projection) ValueError: Unknown projection '3d' fig的類型: <class 'matplotlib.figure.Figure'> fig:Figure(640x480) Process finished with exit code 1解決辦法
在開頭加上這句代碼
from mpl_toolkits.mplot3d import Axes3D然后就可以運行了
參考文章1:深入淺出python機器學習_如何用python畫三維圖? add_subplot() Axes3D() plot_surface() gca()
參考文章2:python畫圖報錯:Unknown projection ‘3d’
總結
以上是生活随笔為你收集整理的pycharm matplotlib.pyplot.figure().add_subplot()绘制三维图时报错:ValueError: Unknown projection 3d(bug)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【深度学习的数学】激活函数的作用是什么?
- 下一篇: 【深度学习的数学】绘制2×3×1层带si