gpt4 book ai didi

python - 如何扩展或 "zoom"pandasplot()图?

转载 作者:行者123 更新时间:2023-12-01 01:41:59 24 4
gpt4 key购买 nike

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

在:

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

因此,我的问题是如何在图像的该部分上扩展或更接近 pandas 绘图?

最佳答案

仅举一个例子来说明它是如何工作的:

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 附近非常陡峭。

您还可以直接在 pandas 绘图函数中缩放 y 轴:

df.plot(logy=True)

enter image description here

关于python - 如何扩展或 "zoom"pandasplot()图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51787097/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com