NumPy unique: Values, Counts and Unique Rows

NumPy unique: the Command Prompt showing unique values with their counts and the most common value

np.unique() returns the distinct values of a NumPy array, sorted, with duplicates removed. Add return_counts=True and you get how often each one appeared: The sorting is not optional, which is the first thing that surprises people coming from pandas. The axis argument is the second. Runs below are on NumPy 2.5.3, pandas 3.0.6, Python 3.12.5. … Read more >>

Customize xtick Labels Using fontdict and fontsize in Matplotlib

xtick Labels Using fontdict Matplotlib

I have found that clear communication is the soul of any Python visualization. I often see developers create stunning charts, only to have the audience squint at tiny, unreadable axis labels. Matplotlib remains the powerhouse for Python plotting, but its default settings often feel a bit too clinical for high-stakes presentations. When I am building … Read more >>

Set xticks Range and Interval in Matplotlib

Set xticks Range in Matplotlib

I have spent over a decade building data visualizations in Python, and if there is one thing I’ve learned, it’s that default axis ticks are rarely perfect. Often, Matplotlib tries to be helpful by guessing where your ticks should go, but it often ends up cluttering the x-axis or skipping vital data points. In this … Read more >>

Matplotlib Boxplot: Set X-Axis Tick Labels

Matplotlib Boxplot Set X-Axis Tick Labels

In my decade of working as a Python developer, I have spent countless hours staring at data visualizations. One of the most common challenges I see beginners face is making their charts readable for a non-technical audience. When I first started building Python data models, I often struggled with messy axis labels. My boxplots would … Read more >>

Change Tick Direction in Python Matplotlib

Change Tick Direction in Python Matplotlib

If you have spent any time building data visualizations in Python, you know that the “default” look isn’t always what you want for a high-end report. One small detail that often catches my eye—and bugs me—is the direction of the axis ticks. By default, Matplotlib usually points them outward, away from the plot area. In … Read more >>

Matplotlib set_xticklabels: Custom X-Axis Labels

Matplotlib set_xticklabels: a bar chart with numeric labels, month names, and month names rotated and right-aligned

set_xticklabels replaces the text under each x-axis tick in Matplotlib. It changes the words, not where the ticks sit, so the positions have to be settled first: Skip that first line and Matplotlib warns you, because it can no longer promise the labels line up with the data. There’s a newer one-call form too, further … Read more >>

Python Percent Symbol (%)

percentage symbol in python

In my decade of building Python applications, I’ve found that few symbols are as versatile as the percent sign (%). While most beginners think it’s just for calculating remainders, it actually wears many hats in a professional codebase. I remember early in my career when I had to format complex financial reports for a New … Read more >>

Matplotlib fill_between: Shading Between Two Curves

Matplotlib fill_between: three sine plots showing a basic fill, conditional shading with gaps, and the same with interpolate set to True

fill_between shades the area between two curves in Matplotlib. Give it the x values and one y series and it fills down to zero; give it two and it fills the gap between them. The two arguments that cause trouble are where=, for shading only part of the range, and interpolate=True, which you almost always … Read more >>

NumPy Factorial: Why np.factorial Fails and What to Use

NumPy factorial: the Command Prompt showing that np.factorial does not exist and raises an AttributeError

There is no NumPy factorial function. np.factorial() doesn’t exist and never has, which is why you’re here after an AttributeError. Use math.factorial for a single integer and scipy.special.factorial for a whole array. The rest of this page is the detail that decides between them. Versions used below: NumPy 2.5.3, SciPy 1.18.1, Python 3.12.5. Why does … Read more >>