python - “ImportError:选择默认后端“matplotlib”时,绘图需要 matplotlib。”
问题描述
无法理解为什么我会收到此错误以及如何修复它。我正在尝试为附近的列表数量绘制图表。我试过卸载然后重新安装熊猫,但它似乎不起作用
通过运行以下代码:
feq=listings['neighbourhood'].value_counts().sort_values(ascending=True)
feq.plot.barh(figsize=(10, 8), color='b', width=1)
plt.title("Number of listings by neighbourhood", fontsize=20)
plt.xlabel('Number of listings', fontsize=12)
plt.show()
遇到此错误:
ImportError: matplotlib is required for plotting when the default backend "matplotlib" is selected.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
C:\Users\DIKSHA~1\AppData\Local\Temp/ipykernel_2704/2039381319.py in <module>
1 feq=listings['neighbourhood'].value_counts().sort_values(ascending=True)
----> 2 feq.plot.barh(figsize=(10, 8), color='b', width=1)
3 plt.title("Number of listings by neighbourhood", fontsize=20)
4 plt.xlabel('Number of listings', fontsize=12)
5 plt.show()
~\anaconda3\lib\site-packages\pandas\plotting\_core.py in barh(self, x, y, **kwargs)
1197 >>> index = ['snail', 'pig', 'elephant',
1198 ... 'rabbit', 'giraffe', 'coyote', 'horse']
-> 1199 >>> df = pd.DataFrame({'speed': speed,
1200 ... 'lifespan': lifespan}, index=index)
1201 >>> ax = df.plot.barh(x='lifespan')
~\anaconda3\lib\site-packages\pandas\plotting\_core.py in __call__(self, *args, **kwargs)
873 "arguments, only keyword arguments. The order of "
874 "positional arguments will change in the future. "
--> 875 f"Use `Series.plot({keyword_args})` instead of "
876 f"`Series.plot({positional_args})`."
877 )
~\anaconda3\lib\site-packages\pandas\plotting\_core.py in _get_plot_backend(backend)
1784 f"Could not find plotting backend '{backend}'. Ensure that you've "
1785 f"installed the package providing the '{backend}' entrypoint, or that "
-> 1786 "the package has a top-level `.plot` method."
1787 )
1788
ImportError: matplotlib is required for plotting when the default backend "matplotlib" is selected.
解决方案
我用“barh”(feq.plot.barh(figsize=(10, 8), color='b', width=1))拼错了 bar ,导致了这个错误。
推荐阅读
- python - OSError: [WinError 123] La syntaxe du nom de fichier, de répertoire ou de volume est wronge: '
' - python - 为什么 .loc 在 Python Pandas 系列中不起作用?
- c - pthread 不让你知道吗?
- scala - Graphiql 中标记为非空的所有字段和参数:Sangria,scala
- html - 将页脚添加到 Angular Material Datepicker
- bash - Bash - 重复输入 n 次(用户输入)
- node.js - 如何使用 dotnet cli 安装“Node JS Tools”
- html - iPhone Safari 中的 PNG 图像呈现光栅化问题
- c# - 应用类中的值时,C#表单文本框不刷新
- ios - 如何在离子中为 WKWebView 实现自定义 NSURLProtocol?