python - 如何使我的 DataFrame.plot 子图在线发布?
问题描述
我试图了解 pandas.DataFrame.plot 的工作原理,但坚持将几个子图排成一行。我感到很困惑,所以我的问题可能听起来很奇怪。但我会很感激任何帮助。
recent_grads.plot(x = "Women", y = "Median", kind = "scatter", subplots = True, figsize=(6, 6), layout = (2,2), sharex = False)
recent_grads.plot(x = "Men", y = "Median", kind = "scatter", subplots = True, figsize=(6, 6), layout = (2,2), sharex = False)
我正在将我的子图放在另一个之下,但我希望它们保持一致。
解决方案
你可以plt.subplots
使用matplotlib.pyplot
import matplotlib.pyplot as plt
fig, ax = plt.subplots(nrows=1, ncols=2)
fig.set_size_inches(6, 6)
plt.subplots_adjust(wspace=0.2)
recent_grads.plot(x = "Women", y = "Median", kind = "scatter", ax=ax[0], sharex = False)
recent_grads.plot(x = "Men", y = "Median", kind = "scatter", ax=ax[1], sharex = False)
推荐阅读
- c++ - ATL 类对象的日志记录
- python - Pickle dump-load 似乎修改了 numpy 数据
- ruby-on-rails - Rails _ 用户关系之友
- python - 安装 tensorflow(AVX 支持)和 cpuid python 时出错
- django - 在 Django REST 框架中,如何告诉我的序列化程序更新成员字段,而不是尝试从头开始创建它?
- javascript - nodejs上的fetch api问题
- javascript - 如何使用 Javascript 获取多个对象数组的每种组合
- python - How to check if tuple key contains an element in dictionary
- sql-server - 如何解决连接到 SQL Server 的错误
- kubernetes - 如何在 Kubernetes 中挂载单个非配置文件?