Avi*_*Dey 7 python matplotlib seaborn
为什么每当我尝试使用 seaborn 中的 FacetGrid 时总是收到此警告?
UserWarning: The figure layout has changed to tight.
self._figure.tight_layout(*args, **kwargs)
我知道这是一个警告而不是错误,我也知道它正在将布局更改为紧凑。我的问题是为什么它首先出现?我错过了什么吗?
示例代码:
import seaborn as sns
penguins = sns.load_dataset("penguins")
g = sns.FacetGrid(penguins, col="island")
g.map_dataframe(sns.histplot, x="bill_length_mm")
Run Code Online (Sandbox Code Playgroud)
此代码会引发该警告。
我究竟做错了什么?
我知道我可以用警告模块隐藏它们,但我不想这样做。
正如评论中提到的,这是一个matplotlib 错误。它在 3.7.3 版本中已修复,因此您可以通过升级 Matplotlib 来避免它。
\n其中一条评论建议调用plt.figure(..., layout=\'constrained\'), 而不是tight_layout(),这与我在文档中找到的一些评论相匹配,例如Constrained Layout Guide:
\n\n约束布局与紧密布局类似,但更加灵活。
\n
我看到这个警告,因为我正在调用subplots(),然后重复绘图,调用tight_layout(),保存图形,然后调用cla()。
tight_layout()我通过从循环中删除对 的调用并调用 来修复它subplots(..., layout=\'tight\')。
请注意,您可能需要 Python 3.11 来运行 matplotlib 3.7.3,正如 Python 3.10 的测试所示:
\nconda install matplotlib[version=\'>=3.7.3\']\nRun Code Online (Sandbox Code Playgroud)\n输出:
\nRetrieving notices: ...working... done\nChannels:\n - defaults\nPlatform: linux-64\nCollecting package metadata (repodata.json): done\nSolving environment: \\ warning libmamba Added empty dependency for problem type SOLVER_RULE_UPDATE\nfailed\n\nLibMambaUnsatisfiableError: Encountered problems while solving:\n - package matplotlib-3.8.0-py311h06a4308_0 requires matplotlib-base >=3.8.0,<3.8.1.0a0, but none of the providers can be installed\n\nCould not solve for environment specs\nThe following packages are incompatible\n\xe2\x94\x9c\xe2\x94\x80 matplotlib-base 3.7.2.* is installable with the potential options\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 matplotlib-base 3.7.2, which can be installed;\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 matplotlib-base [3.7.2|3.8.0] would require\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80 python >=3.10,<3.11.0a0 , which can be installed;\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 matplotlib-base 3.7.2 would require\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80 python >=3.8,<3.9.0a0 , which can be installed;\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80 matplotlib-base [3.7.2|3.8.0] would require\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80 python >=3.9,<3.10.0a0 , which can be installed;\n\xe2\x94\x9c\xe2\x94\x80 matplotlib >=3.7.3 is installable with the potential options\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 matplotlib 3.8.0 would require\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80 matplotlib-base >=3.8.0,<3.8.1.0a0 with the potential options\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 matplotlib-base [3.7.2|3.8.0], which can be installed (as previously explained);\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 matplotlib-base [3.7.2|3.8.0], which can be installed (as previously explained);\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 matplotlib-base 3.8.0 conflicts with any installable versions previously reported;\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80 matplotlib-base 3.8.0 would require\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80 python >=3.12,<3.13.0a0 , which can be installed;\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 matplotlib 3.8.0 would require\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80 python >=3.10,<3.11.0a0 , which can be installed;\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 matplotlib 3.8.0 would require\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80 python >=3.12,<3.13.0a0 , which can be installed;\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80 matplotlib 3.8.0 would require\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80 python >=3.9,<3.10.0a0 , which can be installed;\n\xe2\x94\x94\xe2\x94\x80 pin-1 is not installable because it requires\n \xe2\x94\x94\xe2\x94\x80 python 3.11.* , which conflicts with any installable versions previously reported.\n\nPins seem to be involved in the conflict. Currently pinned specs:\n - python 3.11.* (labeled as \'pin-1\')\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
8272 次 |
| 最近记录: |