Stem & Leaf Plot
Chart overview
Stem and leaf plots display data distribution in a text-based format that preserves actual data values.
Key points
- Each value is split into a stem (leading digits) and leaf (trailing digit), creating a hybrid of a histogram and a data listing that's useful for small to medium datasets.
- Their niche is deliberate: for roughly 15-150 observations you get a histogram's shape and the raw values in one artifact, so a reader can recompute the median or spot a repeated value - a digit-preference artifact, or a sensor that only reports even numbers - that binning would erase.
- That makes them genuinely useful in lab notebooks, teaching, and data-quality checks more than in journal figures.
Practical guidance
Python support is thin, and that's normal: the stemgraphic package produces publication-style displays including back-to-back comparisons of two samples, while a plain-text version is a few lines of standard-library code; matplotlib is only needed to typeset one inside a figure. Choose the stem unit so you get about 5-15 stems - too fine and every row holds one leaf, too coarse and the shape disappears; split stems (leaves 0-4 and 5-9 on separate rows) rescue awkward ranges. Always sort the leaves and state the leaf unit (e. g. leaf = 0. 1 s) in a key, since the display is meaningless without it. Beyond a few hundred points, switch to a histogram or dot plot.
Create a Stem & Leaf Plot with your data using AI — no coding required.
Python Tutorial
How to create a stem & leaf plot in Python
Use the full tutorial for implementation details, troubleshooting, and chart variations in matplotlib, seaborn, and plotly.
How to Build Line Plots and Time Series in R with ggplot2Example Visualization
.png&w=1280&q=70)
Create This Chart Now
Generate publication-ready stem & leaf plots with AI in seconds. No coding required – just describe your data and let AI do the work.
View example prompt
"Create a stem-and-leaf plot showing 'Final Exam Scores' for a statistics class of 35 students. Generate realistic grade data with a slight negative skew (most students passing): scores ranging from 52 to 98, mean ~78, median ~80. Stem represents tens digit (5-9), leaves are units digits. Order leaves from lowest to highest within each stem. Include a key showing '7|5 = 75'. Add summary statistics below: n=35, min=52, Q1=72, median=80, Q3=86, max=98, mean=77.8, SD=11.2. Mark the passing grade (70) with an annotation. Highlight the mode(s). Compare distribution shape to normal. Title: 'Statistics 101 Final Exam Score Distribution'."
How to create this chart in 30 seconds
Upload Data
Drag & drop your Excel or CSV file. Plotivy securely processes it in your browser.
AI Generation
Our AI analyzes your data and generates the Stem & Leaf Plot code automatically.
Customize & Export
Tweak the design with natural language, then export as high-res PNG, SVG or PDF.
Newsletter
Get one weekly tip for better stem & leaf plots
Join researchers receiving concise Python plotting techniques to improve chart clarity and reduce revision cycles.
Python Code Example
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
# Generate realistic exam scores with slight negative skew
np.random.seed(42)
# Create a negatively skewed distribution
scores = np.random.normal(loc=82, scale=10, size=35)
# Apply negative skew transformation
scores = scores - 0.5 * (scores - np.mean(scores))**2 / np.std(scores)
# Clip to range and round
scores = np.clip(scores, 52, 98)
scores = np.round(scores).astype(int)
# Adjust to meet exact requirements
while len(scores) != 35 or np.mean(scores) < 77 or np.mean(scores) > 79 or np.median(scores) < 79 or np.median(scores) > 81:
scores = np.random.normal(loc=82, scale=10, size=35)
scores = scores - 0.5 * (scores - np.mean(scores))**2 / np.std(scores)
scores = np.clip(scores, 52, 98)
scores = np.round(scores).astype(int)
# Sort scores for stem-and-leaf
scores_sorted = np.sort(scores)
# Create stem-and-leaf plot data
stem_leaf = {}
for score in scores_sorted:
stem = score // 10
leaf = score % 10
if stem not in stem_leaf:
stem_leaf[stem] = []
stem_leaf[stem].append(leaf)
# Sort leaves within each stem
for stem in stem_leaf:
stem_leaf[stem].sort()
# Calculate statistics
n = len(scores)
min_score = np.min(scores)
q1 = np.percentile(scores, 25)
median = np.median(scores)
q3 = np.percentile(scores, 75)
max_score = np.max(scores)
mean_score = np.mean(scores)
std_score = np.std(scores)
# Find mode(s)
unique, counts = np.unique(scores, return_counts=True)
max_count = np.max(counts)
modes = unique[counts == max_count]
# Create the plot
fig, ax = plt.subplots(figsize=(12, 10))
ax.set_xlim(-10, 10)
ax.set_ylim(-10, 10)
ax.axis('off')
# Title
plt.text(0, 9, 'Statistics 101 Final Exam Score Distribution',
fontsize=16, fontweight='bold', ha='center')
# Stem-and-leaf plot
y_pos = 7
plt.text(-8, y_pos, 'Stem-and-Leaf Plot:', fontsize=12, fontweight='bold')
y_pos -= 0.8
for stem in sorted(stem_leaf.keys()):
leaves_str = ' '.join([str(leaf) for leaf in stem_leaf[stem]])
plt.text(-6, y_pos, f'{stem} | {leaves_str}', fontsize=11, family='monospace')
y_pos -= 0.6
# Key
y_pos -= 0.5
plt.text(-6, y_pos, 'Key: 7 | 5 = 75', fontsize=10, style='italic')
# Mark passing grade (70)
y_pos -= 1.5
plt.text(-8, y_pos, 'Passing Grade (70):', fontsize=11, fontweight='bold')
y_pos -= 0.6
plt.text(-6, y_pos, '← Students below this score need remediation', fontsize=10)
# Highlight mode(s)
y_pos -= 1.2
plt.text(-8, y_pos, f'Mode(s): {", ".join(map(str, modes))} (appears {max_count} times)',
fontsize=11, fontweight='bold', color='red')
# Summary statistics
y_pos -= 1.5
plt.text(-8, y_pos, 'Summary Statistics:', fontsize=12, fontweight='bold')
stats_text = [
f'n = {n}',
f'Min = {min_score}',
f'Q1 = {q1:.1f}',
f'Median = {median:.1f}',
f'Q3 = {q3:.1f}',
f'Max = {max_score}',
f'Mean = {mean_score:.1f}',
f'SD = {std_score:.1f}'
]
y_pos -= 0.8
for stat in stats_text:
plt.text(-6, y_pos, stat, fontsize=10)
y_pos -= 0.5
# Distribution shape comparison
y_pos -= 0.8
plt.text(-8, y_pos, 'Distribution Shape:', fontsize=11, fontweight='bold')
y_pos -= 0.6
skewness = stats.skew(scores)
if skewness < -0.5:
shape = 'Negatively skewed (left tail)'
elif skewness > 0.5:
shape = 'Positively skewed (right tail)'
else:
shape = 'Approximately normal'
plt.text(-6, y_pos, f'{shape} (skewness = {skewness:.2f})', fontsize=10)
# Add a simple histogram representation on the right
ax2 = fig.add_axes([0.55, 0.15, 0.35, 0.35])
ax2.hist(scores, bins=15, edgecolor='black', alpha=0.7, color='skyblue')
ax2.axvline(x=70, color='red', linestyle='--', linewidth=2, label='Passing Grade')
ax2.set_xlabel('Score', fontsize=10)
ax2.set_ylabel('Frequency', fontsize=10)
ax2.set_title('Score Distribution', fontsize=11)
ax2.legend(fontsize=9)
ax2.grid(True, alpha=0.3)
plt.tight_layout()
plt.savefig('exam_scores_analysis.png', dpi=300, bbox_inches='tight')
plt.show()
# END-OF-CODEOpens the Analyze page with this code pre-loaded and ready to execute
Console Output
5 | 2 2 7 8 7 | 1 1 3 6 6 6 7 8 8 8 9 8 | 0 0 0 2 2 2 2 3 3 3 3 4 4 4 4 4 5 5 5 5 Key: 7 | 5 = 75 n = 35, Median = 80.0, Mode = 84 (appears 5 times)
Common Use Cases
- 1Exploratory data analysis
- 2Small dataset visualization
- 3Educational statistics
- 4Quick distribution assessment
Pro Tips
Best for datasets under 100 values
Include a key showing scale
Consider back-to-back for comparisons
Frequently asked questions
When should you use a stem & leaf plot?
Stem and leaf plots display data distribution in a text-based format that preserves actual data values. Each value is split into a stem (leading digits) and leaf (trailing digit), creating a hybrid of a histogram and a data listing that's useful for small to medium datasets. Common applications include exploratory data analysis, small dataset visualization, and educational statistics.
Which Python libraries can create a stem & leaf plot?
A stem & leaf plot can be built in Python with stemgraphic and matplotlib — stemgraphic and matplotlib for precise control over axes, annotations, and journal styling. In Plotivy you describe the figure and it writes the stemgraphic code for you.
Can I make a stem & leaf plot without writing Python code?
Yes. Describe the stem & leaf plot you need in plain language and upload your dataset — Plotivy's AI writes the Python code and renders a publication-ready figure. You still get the full, editable stemgraphic source, so nothing is locked in a black box.
What are best practices for a clear stem & leaf plot?
Best for datasets under 100 values. Include a key showing scale.
Long-tail keyword opportunities
High-intent chart variations
Library comparison for this chart
stemgraphic
Useful in specialized workflows that complement core Python plotting libraries for stem-and-leaf-plot analysis tasks.
matplotlib
Best when you need full control over axis formatting, annotation placement, and journal-specific styling for stem-and-leaf-plot.
Scientific Chart Selection Cheat Sheet
Not sure whether to use a Violin Plot, Box Plot, or Ridge Plot? Download our single-page reference mapping the most-used scientific chart types, exactly when to use them, and the core Matplotlib/Seaborn functions.