holtzy / holtzy/The-Python-Graph-Gallery
bug
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 2.2k
- Forks
- 438
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue points to the Graph Gallery's “Show Number of Observations” Python example; start by checking the boxplot setup and the later ax.get_xticklabels() use. Confirm the example runs and renders the observation-count labels, then inspect other Python examples for the same reported mistake.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, pandas, python
- Domain
- data-visualization, documentation
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100