首页 > 解决方案 > 如何使我的 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)

我正在将我的子图放在另一个之下,但我希望它们保持一致。

标签: pythonpandasmatplotlibplotsubplot

解决方案


你可以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)

推荐阅读