Matplotlib created a temporary config/cache directory at C:\Users\Elegent\AppData\Local\Temp\matplotlib-pyrb807h because the default path (C:\Users\Elegent\.matplotlib) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing. Traceback (most recent call last): File "D:\pythonProject\AppleStock\ananly2.py", line 24, in <module> candlestick_ochl(ax, df[["Open", "Close", "Volume", "High", "Low"]].values, width=0.5, colorup="green", colordown="red") File "D:\pythonProject\venv\lib\site-packages\mplfinance\original_flavor.py", line 195, in candlestick_ochl return _candlestick(ax, quotes, width=width, colorup=colorup, File "D:\pythonProject\venv\lib\site-packages\mplfinance\original_flavor.py", line 286, in _candlestick if close >= open: TypeError: '>=' not supported between instances of 'int' and 'str'
时间: 2023-07-03 08:28:15 浏览: 678
这个错误可能是由于您的数据类型不匹配所导致的。您可以尝试将 Close、Open、High 和 Low 这些列的数据类型转换为 float 或者 int 类型。您可以使用以下代码进行转换:
```python
df['Close'] = df['Close'].astype(float)
df['Open'] = df['Open'].astype(float)
df['High'] = df['High'].astype(float)
df['Low'] = df['Low'].astype(float)
```
如果您还遇到了 "MPLCONFIGDIR environment variable not set" 的错误,您可以在代码的开头添加以下代码来设置 MPLCONFIGDIR 环境变量:
```python
import os
os.environ['MPLCONFIGDIR'] = '/tmp/'
```
这样就可以避免上述警告,同时可以加速 Matplotlib 的导入并提高多进程支持。
相关问题
PS D:\pythonProject> pip install matplotlib Collecting matplotlib Obtaining dependency information for matplotlib from https://files.pythonhosted.org/packages/d0/39/4c4fb38ec2356bcbc9017a5421623aec69aacde110e4e76d34d0a43702f0/matplotlib-3.7.2-cp310-cp310-win32.whl.metadata Using cached matplotlib-3.7.2-cp310-cp310-win32.whl.metadata (5.8 kB) Collecting contourpy>=1.0.1 (from matplotlib) Using cached contourpy-1.1.0.tar.gz (13.4 MB) Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... error error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [25 lines of output] + meson setup C:\Users\张豪\AppData\Local\Temp\pip-install-fuirjkwl\contourpy_ab1b9965df3941b882963f3350114322 C:\Users\张豪\AppData\Local\Temp\pip-install-fuirjkwl\contourpy_ab1 b9965df3941b882963f3350114322\.mesonpy-qrhmsqrm\build -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --vsenv --native-file=C:\Users\张豪\AppData\Local\Temp\pip-install-fuirjkwl\contourpy_ab1b9965df3941b882963f3350114322\.mesonpy-qrhmsqrm\build\meson-python-native-file.ini The Meson build system Version: 1.2.0 Source dir: C:\Users\张豪\AppData\Local\Temp\pip-install-fuirjkwl\contourpy_ab1b9965df3941b882963f3350114322 Build dir: C:\Users\张豪\AppData\Local\Temp\pip-install-fuirjkwl\contourpy_ab1b9965df3941b882963f3350114322\.mesonpy-qrhmsqrm\build Build type: native build Project name: contourpy Project version: 1.1.0 Activating VS 17.6.5 note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details.
这个错误是由于缺少构建依赖项导致的。在安装 matplotlib 之前,您需要安装一些必要的库。请按照以下步骤操作:
1. 打开命令提示符或终端,并确保您的计算机已连接到互联网。
2. 运行以下命令来安装构建工具:
```
pip install build
```
3. 安装完构建工具后,再次尝试安装 matplotlib:
```
pip install matplotlib
```
这样应该可以解决您遇到的问题。如果仍然有任何疑问,请随时提问。
阅读全文