Matplotlib

np.polyfit() — Curve Fitting with NumPy Polyfit

The .polyfit() function, accepts three different input values: x, y and the polynomial degree. Arguments x and y correspond to the values of the data points that we want to fit, on the x and y axes, respectively. The third parameter specifies the degree of our polynomial function. For example, to obtain a linear fit, …

np.polyfit() — Curve Fitting with NumPy Polyfit Read More »

Matplotlib Histogram — A Simple Illustrated Guide

The histogram is one of the most important plots for you to know. You’ll use it every time you explore a dataset. It is the go-to plot for plotting one variable.  In this article, you’ll learn the basics and some intermediate ideas. You’ll plot histograms like a pro in no time using Python and matplotlib. …

Matplotlib Histogram — A Simple Illustrated Guide Read More »

Photo by Gensa Hub on Unsplash

Matplotlib Animation – A Helpful Illustrated Guide

Creating animations in matplotlib is reasonably straightforward. However, it can be tricky when starting, and there is no consensus for the best way to create them. In this article, I show you a few methods you can use to make amazing animations in matplotlib. Matplotlib Animation Example The hardest thing about creating animations in matplotlib …

Matplotlib Animation – A Helpful Illustrated Guide Read More »

Python Lists filter() vs List Comprehension – Which is Faster?

[Spoiler] Which function filters a list faster: filter() vs list comprehension? For large lists with one million elements, filtering lists with list comprehension is 40% faster than the built-in filter() method. To answer this question, I’ve written a short script that tests the runtime performance of filtering large lists of increasing sizes using the filter() …

Python Lists filter() vs List Comprehension – Which is Faster? Read More »

Legends add clarity to complex plots

Matplotlib Legend – A Helpful Illustrated Guide

You’ve plotted some data in Matplotlib but you don’t know which data shows what? It’s time for a legend! How to add a legend in Python’s Matplotlib library? Label it with the label keyword argument in your plot method. Before plt.show(), call plt.legend() your plot will be displayed with a legend. Here’s the minimal example: …

Matplotlib Legend – A Helpful Illustrated Guide Read More »