Pandas在绘图时提供kind='kde'
。在我的设置中,我更喜欢kde密度。替代kind='histogram'
提供方向选项:orientation='horizontal'
,这是我正在做的事情所必需的。不幸的是,orientation
不适用于KDE。
至少这是我认为发生的事因为我得到了
in set_lineprops
raise TypeError('There is no line property "%s"' % key)
TypeError: There is no line property "orientation"
字符串
是否有任何直接的替代方案可以像绘制 * 直方图 * 一样简单地绘制 kde?
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
plt.ion()
ser = pd.Series(np.random.random(1000))
ax1 = plt.subplot(2,2,1)
ser.plot(ax = ax1, kind = 'hist')
ax2 = plt.subplot(2,2,2)
ser.plot(ax = ax2, kind = 'kde')
ax3 = plt.subplot(2,2,3)
ser.plot(ax = ax3, kind = 'hist', orientation = 'horizontal')
# not working lines below
ax4 = plt.subplot(2,2,4)
ser.plot(ax = ax4, kind = 'kde', orientation = 'horizontal')
型
的数据
1条答案
按热度按时间zsohkypk1#
pandas.Series.plot.kde
没有更改绘图方向的选项。scipy.stats.gaussian_kde
计算这些值,并使用matplotlib.axes.Axes.plot
将它们绘制在一条线上。seaborn.kdeplot
是一个选项。gaussian_kde
在.plot.kde
和sns.kdeplot
中使用字符串
的数据