如何在 plotnine 中水平绘制密度?
How to plot density horizontally in plotnine?
运行代码:
from plotnine import *
import numpy as np
import pandas as pd
df = pd.DataFrame({'values': np.random.normal(0,10,1000), 'group': ['a']*500 + ['b']*500})
#
plot = (
ggplot(df, aes(x = 'values', y='..density..', fill = 'group'))
+ geom_density(alpha = 0.7)
)
plot
Returns剧情如下:
简单地翻转坐标会导致:
plot+coord_flip()
需要做什么才能让第二个情节看起来正确?
运行代码:
from plotnine import *
import numpy as np
import pandas as pd
df = pd.DataFrame({'values': np.random.normal(0,10,1000), 'group': ['a']*500 + ['b']*500})
#
plot = (
ggplot(df, aes(x = 'values', y='..density..', fill = 'group'))
+ geom_density(alpha = 0.7)
)
plot
Returns剧情如下:
简单地翻转坐标会导致:
plot+coord_flip()
需要做什么才能让第二个情节看起来正确?