如何扩展或“缩放”熊猫plot()图?

时间:2018-08-10 12:58:05

标签: python python-3.x pandas matplotlib

我正在使用pandas plot()函数进行绘图,如下所示:

在:

from matplotlib.pyplot import *
from datetime import date
import matplotlib.dates as mdates
import matplotlib.pyplot as plt

fig, ax = subplots()
df['session_duration_seconds'].sort_index().value_counts().plot(figsize=(25,10), fontsize=24)
ax.legend(['session_duration_seconds'],fontsize=22)
ax.set_xlabel("Title", fontsize=22)
ax.set_ylabel("Title", fontsize=22)
ax.grid()

但是,我的绘图看起来非常“隐藏”,我想扩展该绘图以更详细地显示该图的以下部分:

出局:

enter image description here

因此,我的问题是如何在该图像的该部分上扩大或扩大熊猫图的绘制?

1 个答案:

答案 0 :(得分:1)

仅是一个示例,说明它如何工作:

df = pd.DataFrame({'Values': [1000, 1, 2, 3 , 4 , 2, 5]})
df.plot()

enter image description here

现在让我们限制y范围

import matplotlib.pyplot as plt
df.plot()
plt.ylim(0, 10)

enter image description here

我们会看到曲线的细节。

请注意,由于第一个y值1000引起的巨大斜率,曲线在0附近非常陡峭。

您还可以直接在熊猫图函数中缩放y轴形式:

df.plot(logy=True)

enter image description here