Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何添加计数并删除countplot的顶部和右侧脊椎?_Python_Seaborn - Fatal编程技术网

Python 如何添加计数并删除countplot的顶部和右侧脊椎?

Python 如何添加计数并删除countplot的顶部和右侧脊椎?,python,seaborn,Python,Seaborn,如何通过在每个条的顶部添加计数并检索顶部和右侧的线(仅保留x轴和y轴)来改进此图?以一种“灵活”的方式(我的意思是,不仅仅是对于这个图,而且可以轻松地用另一个数据进行复制) 我试着看了一些帖子,比如,甚至是文档(),但我找不到这些东西的答案。IIUC,试试: import numpy as np import pandas as pd from sklearn.datasets import load_iris iris = load_iris() df = pd.DataFrame(data

如何通过在每个条的顶部添加计数并检索顶部和右侧的线(仅保留x轴和y轴)来改进此图?以一种“灵活”的方式(我的意思是,不仅仅是对于这个图,而且可以轻松地用另一个数据进行复制)

我试着看了一些帖子,比如,甚至是文档(),但我找不到这些东西的答案。

IIUC,试试:

import numpy as np
import pandas as pd
from sklearn.datasets import load_iris

iris = load_iris()
df = pd.DataFrame(data= np.c_[iris['data'], iris['target']],
                 columns= iris['feature_names'] + ['target'])
ax = sns.countplot(df['target']);
for p in ax.patches:
    height = p.get_height()
    ax.text(p.get_x()+p.get_width()/2.,
            height + 3,
            f'{p.get_height()}',
            ha="center") 
    
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
输出:


类似于,但省略了除以
总数的除法来去除脊椎:这个“高度”来自哪里?我试着运行脚本,但它没有意识到这一点variable@DumbML哎呀。我不小心拆下了一根线。更新答案。太好了,非常感谢!还有一件事,如果不是太多的话,我怎样才能增加酒吧标签的大小呢?我怎样才能多赚50英镑?plt.xticks?尝试:
ax.tick_参数(axis='x',labelsize=50)
ax.text(p.get_x()+p.get_width()/2.,height+3,f'{p.get_height()}',ha=“center”,fontsize=50)
将fontsize参数添加到ax.text方法中。
import numpy as np
import pandas as pd
from sklearn.datasets import load_iris

iris = load_iris()
df = pd.DataFrame(data= np.c_[iris['data'], iris['target']],
                 columns= iris['feature_names'] + ['target'])
ax = sns.countplot(df['target']);
for p in ax.patches:
    height = p.get_height()
    ax.text(p.get_x()+p.get_width()/2.,
            height + 3,
            f'{p.get_height()}',
            ha="center") 
    
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)