Published and tested 22 November 2026.
Which code change produces this result?
I sort the eight input p-values, multiply by test count divided by rank, apply a reverse cumulative minimum, then restore the original feature order. The plot uses supplied log2 fold changes; its dashed horizontal line remains a raw-p reference.
This article uses simulated example data.


What changes in the actual output?
Six points meet raw p<=0.05, while five meet BH q<=0.05. The point with p=0.04 has q about 0.05333 and changes color; neither its coordinates nor the input tests are removed.
| feature | log2_fold_change | input_p | bh_q |
|---|---|---|---|
| 1 | -2.0 | 0.001 | 0.008 |
| 2 | -1.5 | 0.01 | 0.02666666666666667 |
| 3 | -0.5 | 0.03 | 0.048 |
| 4 | 0.2 | 0.2 | 0.2285714285714286 |
| 5 | 0.8 | 0.4 | 0.4 |
| 6 | 1.2 | 0.04 | 0.05333333333333334 |
| 7 | 1.8 | 0.02 | 0.04 |
| 8 | 2.5 | 0.008 | 0.02666666666666667 |
The table shows all input rows. (8)
What should I check before using this setting?
Include the full intended family of tests in the adjustment and check BH dependence assumptions. Colors encode adjusted input p-values; this example applies only that color rule.
How can I reproduce the figures?
Run python example.py in a writable folder. Tested with Python 3.12.4, Matplotlib 3.8.4 and NumPy 1.26.4. The script writes data.csv, before.png, after.png and after.pdf beside itself.
These are the code, data and result files used in this article. Choose a file below to run the example or compare your results.
- example.pyComplete example code to run on your computer.
- data.csvThe input data used in the example; open it as a table.
- before.pngThe figure before the change, for comparison.
- after.pngThe figure after applying the settings in this article.
- after.pdfThe result in PDF format, for viewing and page layout.
- Usage license · LICENSE.txtTerms for reusing the code, data and figures, with source and font notices.
File verification
- hashes.jsonChecksums for checking whether the downloaded files are complete.
Complete Python code
# Original Bopbun code/data: CC0-1.0. Font rights remain separate; see LICENSE.txt.
# Tested: Python 3.12.4, Matplotlib 3.8.4, NumPy 1.26.4.
from pathlib import Path
import csv
import json
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib import colors, ticker, dates
OUT=Path(__file__).resolve().parent
plt.rcdefaults()
plt.rcParams.update({'font.family':'DejaVu Sans','font.size':11,'figure.dpi':120,
'savefig.dpi':160,'pdf.fonttype':42})
def data_file(header,rows):
with (OUT/'data.csv').open('w',newline='',encoding='utf-8') as f:
w=csv.writer(f);w.writerow(header);w.writerows(rows)
def canvas(**kw):
return plt.subplots(figsize=(7.2,4.5),layout='constrained',**kw)
def adjusted(p):
order=np.argsort(p);ranked=p[order];q=np.minimum.accumulate((ranked*len(p)/np.arange(1,len(p)+1))[::-1])[::-1]
result=np.empty_like(p);result[order]=np.minimum(q,1);return result
def make(fixed):
fc=np.array([-2.,-1.5,-.5,.2,.8,1.2,1.8,2.5]);p=np.array([.001,.01,.03,.2,.4,.04,.02,.008]);q=adjusted(p)
data_file(['feature','log2_fold_change','input_p','bh_q'],zip(range(1,9),fc,p,q));fig,ax=canvas();selected=(q if fixed else p)<=.05
ax.scatter(fc,-np.log10(p),c=np.where(selected,'#b84632','#536d82'))
ax.axhline(-np.log10(.05),color='gray',linestyle='--',label='Raw p = 0.05 reference')
ax.set(xlabel='Illustrative log2 fold change',ylabel='-log10(input p)',title='Color by BH q <= 0.05' if fixed else 'Color by raw p <= 0.05');ax.legend(fontsize=9);return fig
if __name__=='__main__':
before=make(False);after=make(True)
before.savefig(OUT/'before.png');after.savefig(OUT/'after.png')
after.savefig(OUT/'after.pdf',metadata={'CreationDate':None,'ModDate':None})
after.canvas.draw()
print(json.dumps({'axes':len(after.axes),'limits':[{'x':list(a.get_xlim()),'y':list(a.get_ylim())} for a in after.axes]}))
plt.close('all')
Which sources and licenses apply?
Original code and data: CC0-1.0. Figures use DejaVu Sans; its font license remains separate. Install Matplotlib and NumPy locally to run the code.
Learn R

