10 Best Python Libraries for Machine Learning in 2026 (Tested)

Python libraries for machine learning: scikit-learn comparing linear regression and random forest on US home prices

A real-estate team in Austin asked me which Python libraries for machine learning their analysts should learn for home prices. My answer: NumPy, pandas and scikit-learn first, then XGBoost or LightGBM for tables, and PyTorch or Keras only when deep learning is really needed. The trouble with most “top 10” lists is that they rank … Read more >>

Change the Pie Chart Background Color in Matplotlib

Matplotlib pie chart background color example: Q1 2026 bike shop revenue pie chart on a navy background

A Portland bike shop owner asked me for a Q1 2026 revenue pie that matches her navy slide deck instead of sitting on a white box. The fix for a Matplotlib pie chart background color is facecolor on the figure. The axes color only shows after ax.set_frame_on(True), because pie() hides it. Here’s what we’re building: … Read more >>

Change the Pie Chart Title Font Size in Matplotlib

Matplotlib pie chart title font size example: March 2026 household budget pie chart with an 18-point title

To change the matplotlib pie chart title font size, pass fontsize to ax.set_title() or plt.title(), for example fontsize=18. A pie has no axis labels, so its title carries the message, yet it’s only 12 points by default. I’ll show you four ways to size it. The Sample Budget Data for These Pie Charts Every example … Read more >>

Running Shell Commands in Python (subprocess Guide)

Running shell commands in Python: Command Prompt output of subprocess.run capturing a command's output

For running shell commands in Python, use subprocess.run(). Pass the command as a list, add capture_output=True, text=True to get its output as a string, and check returncode to see whether it worked: These examples ran on Windows in Command Prompt with Python 3.12.5; the same subprocess calls work in bash on macOS and Linux with … Read more >>

Python for Loop in One Line (One-Liner Examples)

Python for loop one line: Command Prompt output of list, dict and set comprehensions

A Python for loop on one line can be written two ways: put a short body after the colon, like for x in items: print(x), or, when you’re building a new list, use a comprehension such as [x * 2 for x in items]: I ran each one-liner on Python 3.12.5, and the screenshots come … Read more >>

Matplotlib Date Format: Convert and Format Dates in Python

Matplotlib date format example: Denver bakery sales with US-style month, day and year labels on the x axis

Your dates came in as text, and your chart labels look wrong. Two small steps fix both. In this tutorial, we’ll set a matplotlib date format and convert text, pandas and NumPy dates into values Matplotlib can plot. Quick answer: Convert text with strptime() or pd.to_datetime(), plot it with ax.plot(), then attach a DateFormatter: We … Read more >>

Matplotlib Line Style and Color on Date Charts

Matplotlib date chart with three warehouse lines, each with its own color and line style

A logistics manager in Nevada wants matplotlib line style and color changes on a daily shipments chart: the forecast dashed and each warehouse in its own color. You find an old snippet that passes linestyle to plot_date(), and it crashes. Matplotlib 3.11 removed that function, but ax.plot() takes real dates and the same options. In … Read more >>

Matplotlib Scatter and Multiple Line Charts with Dates

Matplotlib multiple line chart with dates: daily sales for Austin, Denver and Boston stores on one date axis

Many guides still draw date charts with plot_date(). It worked for years, but Matplotlib 3.11 removed it, so those scripts now crash on the first call. In this tutorial, I’ll build matplotlib scatter and multiple line charts with dates using ax.scatter() and ax.plot(), which read Python dates directly. Every script ran on Matplotlib 3.11.2 and … Read more >>

Matplotlib plot_date: What It Did and What to Use Now

Matplotlib plot_date replacement: daily gym check-ins drawn as round markers with ax.plot on a real date axis

Copied an older chart script, ran it, and got an AttributeError on plot_date? Your code isn’t wrong so much as out of date, and the repair takes one line. In this tutorial, we’ll cover what matplotlib plot_date used to do, reproduce the real error, and swap it for ax.plot() on real dates. Quick answer: plot_date() … Read more >>

How to Plot Asymmetric Error Bars in Matplotlib

Asymmetric error bars in Matplotlib: weekend hotel rates for five US cities with longer bars above each median

Say you’re charting 2026 weekend hotel rates, and Seattle’s typical price sits $37.50 above the cheap end but $90.75 below the expensive end. A single plus-or-minus number can’t show that. In this tutorial, I’ll draw Matplotlib asymmetric error bars by passing yerr=[lower, upper] to errorbar(), where both are distances from each point. Every chart below … Read more >>