bug

未关闭
#534 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
numpy, pandas, python

调研方向

该 issue 指向 Graph Gallery 的“Show Number of Observations” Python 示例;首先检查 boxplot 的设置以及后续对 ax.get_xticklabels() 的使用。确认该示例可以运行并渲染观测数量标签,然后检查其他 Python 示例是否存在同样的已报告错误。

由索引模型根据 Issue 内容生成。

描述

Hi Yan,

in the Graph Gallery in some example in Python there are mistakes
for example in the "Show Number of Observations"

import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import pandas as pd

Dataset:

a = pd.DataFrame({ 'group' : np.repeat('A',500), 'value': np.random.normal(10, 5, 500) })
b = pd.DataFrame({ 'group' : np.repeat('B',500), 'value': np.random.normal(13, 1.2, 500) })
c = pd.DataFrame({ 'group' : np.repeat('B',500), 'value': np.random.normal(18, 1.2, 500) })
d = pd.DataFrame({ 'group' : np.repeat('C',20), 'value': np.random.normal(25, 4, 20) })
e = pd.DataFrame({ 'group' : np.repeat('D',100), 'value': np.random.uniform(12, size=100) })
df = pd.concat([a,b,c,d,e])

Start with a basic boxplot

sns.boxplot(x="group", y="value", data=df) # the assignment ax is missing

Calculate number of obs per group & median to position labels

medians = df.groupby(['group'])['value'].median().values
nobs = df.groupby("group").size().values
nobs = [str(x) for x in nobs.tolist()]
nobs = ["n: " + i for i in nobs]

Add it to the plot

pos = range(len(nobs))
for tick,label in zip(pos,ax.get_xticklabels()):
plt.text(pos[tick], medians[tick] + 0.4, nobs[tick], horizontalalignment='center', size='medium', color='w', weight='semibold')

add title

plt.title("Boxplot with number of observation", loc="left")

show the graph

plt.show()

================

Best regards

--Marco

主要语言
HTML
星标
2.3k
派生
439
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

holtzy/The-Python-Graph-Gallery 的其他 Issue

查看 holtzy/The-Python-Graph-Gallery 的全部 Issue

相似的 Issue

更多 Data Visualization Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。