如何使我的数据框.plot子地块排成一行?

2024-03-29 10:11:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我在试着理解图.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)

我要把我的副牌放在另一个下面,但我要它们排成一行。你知道吗


Tags: falsetruedataframeplotmedianlayout我会recent
2条回答

您只需修改layout

recent_grads.plot(x = "Women", y = "Median", kind = "scatter", subplots = True, figsize=(6, 6), layout = (1, 1), sharex = False)
recent_grads.plot(x = "Men", y = "Median", kind = "scatter", subplots = True, figsize=(6, 6), layout = (1, 2), sharex = False)

另一种方法是创建Axes对象并显式指定它们:

from matplotlib import pyplot as plt

fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(6, 6))

ax1, ax2 = axes

recent_grads.plot(x = "Women", y = "Median", kind = "scatter", ax=ax1)
recent_grads.plot(x = "Men", y = "Median", kind = "scatter", ax=ax2)

你可以从matplotlib.pyplot使用plt.subplots

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)

相关问题 更多 >