Python Program to Find the Area of a Rectangle

Python program to find the area of a rectangle: the Command Prompt showing the length, width, area and perimeter printed

The area of a rectangle in Python is length * width. That’s the whole calculation, and here it is as a program you can run: What people usually need on top of that is the version that asks the user for the numbers, and one that survives being given nonsense. Both are below. Each program … Read more >>

Matplotlib set_xticks: Tick Positions and Labels

Matplotlib set_xticks: the same sine curve with default ticks, custom positions, and positions with pi labels

ax.set_xticks() decides where the ticks sit on a Matplotlib x-axis. You pass positions in data coordinates, and optionally the labels to go with them: Positions first. That’s the detail behind most of the trouble people have with it, because setting labels without positions is a different and less reliable thing. Figures and output below are … Read more >>

Introduction to TensorFlow 3.x: What’s New?

Introduction to TensorFlow 3.x

TensorFlow is one of the leading frameworks in artificial intelligence, powering many cutting-edge machine learning solutions worldwide. With the release of TensorFlow 3.x, Google takes another significant step toward more robust, flexible, and scalable ML development. For data scientists, developers, and AI enthusiasts, TensorFlow 3.x brings highly anticipated innovations and enhancements. This post walks you … Read more >>

Create and Customize Dashed Lines in Matplotlib

matplotlib dashed line spacing

As a developer, I’ve worked extensively with Matplotlib for data visualization. One of the most common yet useful ways to enhance your plots is by using dashed lines. In this article, I’ll walk you through everything you need to know about creating and customizing dashed lines in Matplotlib. I’ll share practical tips and different methods … Read more >>

How to Remove Ticks and Tick Labels in Matplotlib

Remove ticks and tick labels in Matplotlib: four subplots comparing default ticks, no ticks, labels removed and tick marks removed

To remove tick labels in Matplotlib but keep the tick marks, use ax.tick_params(labelbottom=False, labelleft=False). To remove the ticks and their labels together, use ax.set_xticks([]) and ax.set_yticks([]) (or plt.xticks([]) with pyplot), and to hide everything including the frame, use ax.axis(“off”). This guide compares all of these on real plots, then shows how to remove tick labels … Read more >>

Add Labels to Matplotlib Bar Charts

matplotlib bar label

While working on a project for my clients, I’ve found that data visualization is essential for communicating insights effectively. Bar charts, in particular, are a go-to choice for comparing categories. But one thing I always make sure to include is value labels on bars. They make charts instantly clearer and more professional, especially when presenting … Read more >>

How to Change the Title Font Size in Matplotlib

Matplotlib title font size examples: three subplots with titles at size 10, x-large and bold 16

To change the title font size in Matplotlib, pass fontsize to the title function: plt.title(“My title”, fontsize=20), or ax.set_title(“My title”, fontsize=20) when you work with axes. The size can be a number of points or a name like “large”. This guide covers the title font size for single plots and subplots, bold titles, the figure … Read more >>

How to Add and Customize the X-Axis Label in Matplotlib

Matplotlib x-axis label example: a bar chart with a bold dark blue x-axis label set with set_xlabel

To add an x-axis label in Matplotlib, call plt.xlabel(“Label”), or ax.set_xlabel(“Label”) when you work with an Axes object (for example after plt.subplots()). Both accept text styling such as fontsize, color and fontweight, plus labelpad and loc for its position. This guide covers the matplotlib x-axis label from the basics to changing tick labels, showing every … Read more >>

Matplotlib tick_params(): Customize Ticks and Tick Labels

Matplotlib tick_params example: major and minor ticks with different lengths and colours and red y tick labels

tick_params() changes how ticks, tick labels and gridlines look in Matplotlib: their direction, length, width, colour, label size, rotation and which sides of the plot show them. Call it on an axes, ax.tick_params(…), or use plt.tick_params(…) for the current axes. It changes existing and future ticks, so you do not need to recreate them. This … Read more >>