{"id":2716,"date":"2026-10-19T04:48:54","date_gmt":"2026-10-19T04:48:54","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=2716"},"modified":"2026-10-20T06:11:32","modified_gmt":"2026-10-20T06:11:32","slug":"data-visualization-in-python-using-matplotlib-tutorial","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/","title":{"rendered":"Data visualization"},"content":{"rendered":"<h1><strong><b>Data Visualization in Python Using Matplotlib: Complete Tutorial<\/b><\/strong><\/h1>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Imagine you have a spreadsheet with ten thousand rows of sales, marks or sensor readings. You could scroll through it for hours and still miss the one pattern that matters. Draw a chart and you see it in seconds. Data visualization is the habit of turning numbers into pictures, and in Python the library that does most of the work is Matplotlib.<\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Matplotlib is the oldest and most widely used plotting library in Python. It draws 2D and 3D charts, it works with NumPy arrays, and many other tools, such as Seaborn and the plotting methods in pandas, are built on top of it. If you learn how Matplotlib thinks, with its figures, axes and plot functions, every other Python charting tool becomes easier.<\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">This tutorial is a complete working reference. We list the main plot types and functions, explain the Figure and Axes classes, and then go through each plot one by one: line, multiplot, subplot2grid, grid, limits, ticks, bar, histogram, pie, scatter, contour, quiver, box, violin, and the 3D line, contour, wireframe and surface plots. Every program has been run. We also add a guide to picking the right chart, the two ways of writing Matplotlib code, and the mistakes beginners make most often.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Introduction to Data Visualization in Python Using Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Here is what Matplotlib gives you.<\/p>\n<ul style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px; padding-left: 24px;\">\n<li style=\"margin: 0 0 8px;\"><strong>2D and 3D plots.<\/strong> Line, bar, pie, scatter, contour and many more, plus 3D surfaces through the mplot3d toolkit.<\/li>\n<li style=\"margin: 0 0 8px;\"><strong>NumPy friendly.<\/strong> It draws NumPy arrays directly.<\/li>\n<li style=\"margin: 0 0 8px;\"><strong>Pyplot.<\/strong> A module of simple commands that works like MATLAB, where each command changes the current figure.<\/li>\n<li style=\"margin: 0 0 8px;\"><strong>Many output formats.<\/strong> Save to PNG, JPG, PDF, SVG and more.<\/li>\n<li style=\"margin: 0 0 8px;\"><strong>Works in many places.<\/strong> Jupyter Notebook, plain Python scripts, and desktop windows built with Tkinter, PyQt or wxPython.<\/li>\n<\/ul>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Install Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Python 2 reached its end of life in 2020, so use Python 3. Current Matplotlib needs Python 3.11 or newer, along with these packages, which pip installs for you: <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">contourpy<\/code>, <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">cycler<\/code>, <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">fonttools<\/code>, <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">kiwisolver<\/code>, <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">numpy<\/code>, <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">packaging<\/code>, <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">pillow<\/code>, <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">pyparsing<\/code> and <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">python-dateutil<\/code>.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">terminal<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">pip install matplotlib numpy<\/pre>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">This tutorial was tested on Python 3.13 with Matplotlib 3.11.2 and NumPy 2.5.3.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Two Ways to Write Matplotlib Code<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">This is the idea that confuses most beginners, so it is worth a minute. Matplotlib has two styles, and the examples below use both.<\/p>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 640px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Pyplot style and object oriented style<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Style<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">How it looks<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">When to use it<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Pyplot style<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">plt.plot(x, y) then plt.title(&#8220;Sales&#8221;)<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Quick, single plots and learning<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Object oriented style<\/th>\n<td style=\"padding: 12px 16px;\">fig, ax = plt.subplots() then ax.plot(x, y) and ax.set_title(&#8220;Sales&#8221;)<\/td>\n<td style=\"padding: 12px 16px;\">Several plots, full control, real projects<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">In the object oriented style, a Figure is the whole window or page, and an Axes is one plot inside it. You will see the methods on an Axes start with <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">set_<\/code>, such as <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">set_title<\/code> and <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">set_xlabel<\/code>.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Types of Plots in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">These are the main plot functions.<\/p>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 520px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Main plot functions<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 140px;\" scope=\"col\">Function<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">What it draws<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">plot<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Lines or markers, the default choice for trends<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">bar<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Vertical bar chart<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">barh<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Horizontal bar chart<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">boxplot<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Box and whisker plot<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">hist<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Histogram<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">hist2d<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">2D histogram, counting points in a grid of cells<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">pie<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Pie chart<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">polar<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Plot on polar coordinates<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">scatter<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Scatter plot of two variables<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">stackplot<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Stacked area plot<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">stem<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Stem plot, lines from a baseline to each value<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">step<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Step plot<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">quiver<\/th>\n<td style=\"padding: 12px 16px;\">Arrows showing direction and size<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Image Functions in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">These three functions read, save and show images. Their names are all lowercase.<\/p>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 480px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Image functions<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 140px;\" scope=\"col\">Function<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">What it does<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">imread<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Reads an image file into an array<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">imsave<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Saves an array as an image file<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">imshow<\/th>\n<td style=\"padding: 12px 16px;\">Shows an array as an image<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\npixels = np.array([[0.0, 0.5, 1.0], [1.0, 0.5, 0.0], [0.0, 1.0, 0.0]])\r\nplt.imsave(\"tiny.png\", pixels, cmap=\"gray\")\r\nimg = plt.imread(\"tiny.png\")\r\nprint(img.shape)\r\nplt.imshow(img)\r\nplt.show()<\/pre>\n<div style=\"background: #1f2937; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">output<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #ffffff;\">(3, 3, 4)<\/pre>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The shape means 3 rows, 3 columns and 4 values per pixel, which are red, green, blue and transparency.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Axes Functions in Matplotlib<\/h2>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 560px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Axes functions<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 170px;\" scope=\"col\">Function<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">What it does<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">axes<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Adds an axes to the figure<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">text<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Adds text at a position on the axes<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">title<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Sets the title of the axes<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">xlabel, ylabel<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Sets the label of the x axis and the y axis<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">xlim, ylim<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Gets or sets the range of the x axis and the y axis<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">xticks, yticks<\/th>\n<td style=\"padding: 12px 16px;\">Gets or sets the tick positions and labels of the x axis and the y axis<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Do not mix up the last two rows. The functions xlim and ylim set the range. The functions xticks and yticks control where the marks sit and what they say.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Figure Functions in Matplotlib<\/h2>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 480px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Figure functions<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 140px;\" scope=\"col\">Function<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">What it does<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">figtext<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Adds text to the figure<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">figure<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Creates a new figure<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">show<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Shows the figure<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">savefig<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Saves the figure to a file<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">close<\/th>\n<td style=\"padding: 12px 16px;\">Closes a figure window<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Figure Class in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The Figure is the top level container. Everything you draw sits inside one. You create it with <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">plt.figure<\/code>.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">g1 = plt.figure()<\/pre>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">You can pass these optional parameters:<\/p>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 560px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Figure parameters<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 140px;\" scope=\"col\">Parameter<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">What it sets<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">figsize<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Width and height in inches, as a pair such as (6, 3)<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">dpi<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Dots per inch, which is the sharpness of the image<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">facecolor<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">The background colour of the figure<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">edgecolor<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">The colour of the border around the figure<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">linewidth<\/th>\n<td style=\"padding: 12px 16px;\">The width of that border<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\ng1 = plt.figure(figsize=(6, 3), dpi=100, facecolor=\"lightgrey\", edgecolor=\"navy\", linewidth=2)\r\nprint(g1.get_size_inches(), g1.dpi)<\/pre>\n<div style=\"background: #1f2937; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">output<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #ffffff;\">[6. 3.] 100<\/pre>\n<\/div>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Axes Class in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">An Axes is the actual plot area, with its own x axis, y axis, title and data. A figure can hold many. You add one by calling <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">add_axes<\/code> with four numbers, which are the left, bottom, width and height as fractions of the figure. So <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">[0.1, 0.1, 0.8, 0.8]<\/code> means a plot that starts 10 percent in from the left and bottom, and takes 80 percent of the width and height.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">fig = plt.figure()\r\nax = fig.add_axes([0.1, 0.1, 0.8, 0.8])<\/pre>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">legend<\/code> method labels the lines or shapes, and its <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">loc<\/code> argument says where to put it. Here are the location codes.<\/p>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 520px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Legend location codes<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Location<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Code<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Location<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Code<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">best<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">0<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">center left<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">6<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">upper right<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">1<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">center right<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">7<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">upper left<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">2<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">lower center<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">8<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">lower left<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">3<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">upper center<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">9<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">lower right<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">4<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">center<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">10<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">right<\/th>\n<td style=\"padding: 12px 16px;\">5<\/td>\n<td style=\"padding: 12px 16px;\"><\/td>\n<td style=\"padding: 12px 16px;\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">axes.plot() in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">plot<\/code> method draws lines or markers. You can add a format string as the third argument, which packs the colour, marker and line style into a short code. For example, <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">rs-<\/code> means red, square markers, solid line. Here is a working example.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\ny = [1, 5, 10, 17, 25, 36, 49, 64]\r\nx1 = [1, 16, 30, 42, 55, 68, 77, 88]\r\nx2 = [1, 6, 12, 18, 28, 40, 52, 65]\r\nfig = plt.figure()\r\nax = fig.add_axes([0.1, 0.1, 0.8, 0.8])\r\nl1 = ax.plot(x1, y, \"rs-\")    # red, square markers, solid line\r\nl2 = ax.plot(x2, y, \"mo--\")   # magenta, circle markers, dashed line\r\nax.legend(labels=(\"Hadoop\", \"Data science\"), loc=\"lower right\")\r\nax.set_title(\"Learners enrolled over time\")\r\nax.set_xlabel(\"Learners enrolled\")\r\nax.set_ylabel(\"Weeks since launch\")\r\nplt.show()<\/pre>\n<\/div>\n<p style=\"margin: 0 0 16px;\"><img loading=\"lazy\" decoding=\"async\" style=\"display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid #d9e0ea; border-radius: 8px;\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/matplot1.png\" alt=\"Line plot with two lines, one red with square markers and one magenta dashed with circle markers, with a legend in the lower right\" width=\"850\" height=\"638\" \/><\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">You will see two rising lines and a legend in the lower right corner. These are the colour codes:<\/p>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 480px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Colour codes<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Code<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Colour<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Code<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Colour<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">b<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Blue<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\">m<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Magenta<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">g<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Green<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\">y<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Yellow<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">r<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Red<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\">k<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Black<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">c<\/th>\n<td style=\"padding: 12px 16px;\">Cyan<\/td>\n<td style=\"padding: 12px 16px; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\">w<\/td>\n<td style=\"padding: 12px 16px;\">White<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Marker Codes in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Markers are the shapes drawn on each data point. Note that the D marker is a diamond.<\/p>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 420px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Marker codes<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 120px;\" scope=\"col\">Code<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Marker<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">&#8220;.&#8221;<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Point<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">&#8220;o&#8221;<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Circle<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">&#8220;x&#8221;<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">X mark<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">&#8220;D&#8221;<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Diamond<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">&#8220;H&#8221;<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Hexagon<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">&#8220;s&#8221;<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Square<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">&#8220;+&#8221;<\/th>\n<td style=\"padding: 12px 16px;\">Plus<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Line Styles in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The dashed style is two hyphens typed together.<\/p>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 420px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Line styles<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 120px;\" scope=\"col\">Code<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Line style<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">&#8220;-&#8220;<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Solid<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">&#8220;&#8211;&#8220;<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Dashed<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">&#8220;-.&#8221;<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Dash dot<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">&#8220;:&#8221;<\/th>\n<td style=\"padding: 12px 16px;\">Dotted<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Multiplot in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">To draw several plots in one figure, use <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">plt.subplots<\/code> with the number of rows and columns. It returns the figure and an array of axes, and you pick each axes by its row and column.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">plt.subplots(nrows, ncols)<\/pre>\n<\/div>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nfig, a = plt.subplots(2, 2)\r\nx = np.arange(2, 8)\r\na[0][0].plot(x, x ** 2)\r\na[0][0].set_title(\"square\")\r\na[0][1].plot(x, np.sqrt(x))\r\na[0][1].set_title(\"square root\")\r\na[1][0].plot(x, np.exp(x))\r\na[1][0].set_title(\"exp\")\r\na[1][1].plot(x, np.log10(x))\r\na[1][1].set_title(\"log\")\r\nfig.tight_layout()\r\nplt.show()<\/pre>\n<\/div>\n<p style=\"margin: 0 0 16px;\"><img loading=\"lazy\" decoding=\"async\" style=\"display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid #d9e0ea; border-radius: 8px;\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/subplot.png\" alt=\"Multiplot output, a 2 by 2 grid of four small plots titled square, square root, exp and log\" width=\"850\" height=\"638\" \/><\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">You will see four small plots, with square and exp rising fast, and square root and log rising slowly. The call <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">tight_layout<\/code> stops the titles from overlapping.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">The subplot2grid Function<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">With <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">subplots<\/code>, every cell is the same size. The function <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">subplot2grid<\/code> lets you place axes at chosen positions in a grid, and let one axes span several rows or columns. The call is <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">plt.subplot2grid(shape, location, rowspan, colspan)<\/code>.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\na1 = plt.subplot2grid((4, 4), (0, 0), colspan=2)\r\na2 = plt.subplot2grid((4, 4), (0, 2), rowspan=3)\r\na3 = plt.subplot2grid((4, 4), (1, 0), rowspan=2, colspan=2)\r\nx = np.arange(1, 10)\r\na2.plot(x, x ** 3)\r\na2.set_title(\"cube\")\r\na1.plot(x, np.exp(x))\r\na1.set_title(\"exp\")\r\na3.plot(x, np.log(x))\r\na3.set_title(\"log\")\r\nplt.tight_layout()\r\nplt.show()<\/pre>\n<\/div>\n<p style=\"margin: 0 0 16px;\"><img loading=\"lazy\" decoding=\"async\" style=\"display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid #d9e0ea; border-radius: 8px;\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/subplot2d.png\" alt=\"subplot2grid output with three plots of different sizes titled exp, cube and log\" width=\"850\" height=\"638\" \/><\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The grid is 4 by 4. The first plot takes the top two cells, the second takes three rows on the right, and the third takes a 2 by 2 block on the left.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Grid in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">grid<\/code> method turns gridlines on or off, and lets you change their colour, line style and width. The short names are <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">ls<\/code> for <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">linestyle<\/code> and <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">lw<\/code> for <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">linewidth<\/code>.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nfig, axes = plt.subplots(1, 3, figsize=(12, 4))\r\nx = np.arange(2, 22)\r\naxes[0].plot(x, x ** 4, \"g\", lw=2)\r\naxes[0].grid(True)\r\naxes[0].set_title(\"default grid\")\r\naxes[1].plot(x, np.exp(x), \"r\")\r\naxes[1].grid(color=\"b\", ls=\"-.\", lw=0.25)\r\naxes[1].set_title(\"custom grid\")\r\naxes[2].plot(x, x)\r\naxes[2].set_title(\"no grid\")\r\nfig.tight_layout()\r\nplt.show()<\/pre>\n<\/div>\n<p style=\"margin: 0 0 16px;\"><img loading=\"lazy\" decoding=\"async\" style=\"display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid #d9e0ea; border-radius: 8px;\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/grid-1024x341.png\" alt=\"Grid output, three plots side by side with a default grid, a custom dash dot grid and no grid\" width=\"850\" height=\"283\" \/><\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Setting Limits in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">By default Matplotlib chooses the range of each axis from your data. The methods <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">set_xlim<\/code> and <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">set_ylim<\/code> let you fix it, which is useful when a few huge values squash everything else. Note that these are two separate methods.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nfig = plt.figure()\r\na1 = fig.add_axes([0.1, 0.1, 0.8, 0.8])\r\nx = np.arange(1, 90)\r\na1.plot(x, np.exp(x), \"r\")\r\na1.set_title(\"exp\")\r\na1.set_ylim(0, 80000)\r\na1.set_xlim(0, 10)\r\nplt.show()<\/pre>\n<\/div>\n<p style=\"margin: 0 0 16px;\"><img loading=\"lazy\" decoding=\"async\" style=\"display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid #d9e0ea; border-radius: 8px;\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/limit.png\" alt=\"Setting limits output, a red exponential curve cut to the x range 0 to 10\" width=\"850\" height=\"719\" \/><\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Without the limits, the curve would reach a number with 39 digits and the early part would look flat. With the limits, you see the rise clearly.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Setting Ticks and Tick Labels<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Ticks are the small marks along an axis. Tick labels are the text next to them. Use <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">set_xticks<\/code> and <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">set_yticks<\/code> to choose the positions, and <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">set_xticklabels<\/code> and <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">set_yticklabels<\/code> to choose the text.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\nimport math\r\n\r\nx = np.arange(0, math.pi * 4, 0.04)\r\nfig = plt.figure()\r\nax = fig.add_axes([0.1, 0.1, 0.8, 0.8])\r\nax.plot(x, np.sin(x))\r\nax.set_xlabel(\"angle\")\r\nax.set_title(\"sine\")\r\nax.set_xticks([0, 3, 6, 9])\r\nax.set_xticklabels([\"a\", \"b\", \"c\", \"d\"])\r\nax.set_yticks([-1, 0, 1])\r\nplt.show()<\/pre>\n<\/div>\n<p style=\"margin: 0 0 16px;\"><img loading=\"lazy\" decoding=\"async\" style=\"display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid #d9e0ea; border-radius: 8px;\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/ticklables.png\" alt=\"Setting ticks output, a sine wave with custom x tick labels a, b, c and d\" width=\"850\" height=\"638\" \/><\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The x axis now shows the letters a to d at positions 0, 3, 6 and 9, and the y axis shows only minus 1, 0 and 1.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Bar Plot in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">A bar plot compares values across categories. Use <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">bar<\/code> for vertical bars and <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">barh<\/code> for horizontal ones. These are its main parameters.<\/p>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 560px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Bar plot parameters<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 140px;\" scope=\"col\">Parameter<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">What it sets<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">x<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">The positions of the bars on the x axis<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">height<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">The height of each bar<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">width<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">The width of each bar, 0.8 by default<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">bottom<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Where each bar starts on the y axis, used for stacking<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">align<\/th>\n<td style=\"padding: 12px 16px;\">Whether bars are centred on the position or start at it<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The first example stacks the girls on top of the boys using <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">bottom<\/code>. The stacked totals reach about 267, so the y axis here goes to 300. If you stopped it at 80, the bars would run off the chart.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nN = 5\r\nboysMeans = (120, 135, 130, 135, 127)\r\ngirlsMeans = (125, 132, 134, 120, 125)\r\nind = np.arange(N)  # the x locations for the groups\r\nwidth = 0.35\r\nfig = plt.figure()\r\nax = fig.add_axes([0.1, 0.1, 0.8, 0.8])\r\nax.bar(ind, boysMeans, width, color=\"r\")\r\nax.bar(ind, girlsMeans, width, bottom=boysMeans, color=\"b\")\r\nax.set_ylabel(\"Scores\")\r\nax.set_title(\"Scores by group and gender (stacked)\")\r\nax.set_xticks(ind, (\"G1\", \"G2\", \"G3\", \"G4\", \"G5\"))\r\nax.set_yticks(np.arange(0, 301, 50))\r\nax.legend(labels=[\"boys\", \"girls\"])\r\nplt.show()<\/pre>\n<\/div>\n<p style=\"margin: 0 0 16px;\"><img loading=\"lazy\" decoding=\"async\" style=\"display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid #d9e0ea; border-radius: 8px;\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/bar.png\" alt=\"Stacked bar plot of boys and girls scores for five groups, G1 to G5\" width=\"850\" height=\"638\" \/><\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Stacked bars hide the comparison, because only the bottom bar starts at zero. To compare the two means, put the bars side by side. Shift the boys bars left by half the width, and the girls bars right by half the width.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nind = np.arange(5)\r\nwidth = 0.35\r\nfig, ax = plt.subplots()\r\nax.bar(ind - width \/ 2, (120, 135, 130, 135, 127), width, color=\"r\", label=\"boys\")\r\nax.bar(ind + width \/ 2, (125, 132, 134, 120, 125), width, color=\"b\", label=\"girls\")\r\nax.set_ylabel(\"Scores\")\r\nax.set_title(\"Scores by group and gender (side by side)\")\r\nax.set_xticks(ind, (\"G1\", \"G2\", \"G3\", \"G4\", \"G5\"))\r\nax.legend()\r\nplt.show()<\/pre>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Now the two bars in each group start at zero, and you can see at a glance that the girls beat the boys only in G1 and G3. The call to <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">set_xticks<\/code> with two arguments needs Matplotlib 3.5 or newer.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Histogram in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">A histogram groups numbers into ranges, called bins, and counts how many values fall in each. It shows the shape of a distribution, for example how marks are spread across a class. It is an estimate of the distribution, because the picture changes with the bin choice.<\/p>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 560px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Histogram parameters<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 140px;\" scope=\"col\">Parameter<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">What it sets<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">x<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">The data, as an array or a list<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">bins<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">The number of bins, or a list of bin edges<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">range<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">The lowest and highest values to include<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">density<\/th>\n<td style=\"padding: 12px 16px;\">If True, shows the share of values and not the count<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nfig, ax = plt.subplots(1, 1)\r\na = np.array([22, 87, 5, 43, 56, 73, 55, 54, 11, 20, 51, 5, 79, 31, 27])\r\nax.hist(a, bins=[0, 25, 50, 75, 100])\r\nax.set_title(\"histogram of result\")\r\nax.set_xticks([0, 25, 50, 75, 100])\r\nax.set_xlabel(\"marks\")\r\nax.set_ylabel(\"no. of students\")\r\nplt.show()<\/pre>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The four bars have heights 5, 3, 5 and 2. That means 5 students scored below 25, 3 scored from 25 to 50, 5 from 50 to 75, and 2 from 75 up.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Pie Chart in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">A pie chart shows each value as a share of the whole. It works best with five or fewer slices. These are its main parameters.<\/p>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 560px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Pie chart parameters<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 140px;\" scope=\"col\">Parameter<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">What it sets<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">x<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">The values, one per slice<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">labels<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">The text for each slice<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">colors<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">The colour of each slice<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">autopct<\/th>\n<td style=\"padding: 12px 16px;\">A format string that prints the percentage on each slice<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nfig = plt.figure()\r\nax = fig.add_axes([0.1, 0.1, 0.8, 0.8])\r\nlangs = [\"Statistics\", \"Python\", \"Machine Learning\", \"SQL\", \"Big Data\"]\r\nstudents = [53, 27, 25, 19, 12]\r\nax.pie(students, labels=langs, autopct=\"%1.2f%%\")\r\nplt.show()<\/pre>\n<\/div>\n<p style=\"margin: 0 0 16px;\"><img loading=\"lazy\" decoding=\"async\" style=\"display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid #d9e0ea; border-radius: 8px;\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pie.png\" alt=\"Pie chart of students per subject: Statistics, Python, Machine Learning, SQL and Big Data\" width=\"850\" height=\"638\" \/><\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Statistics gets 38.97 percent, Python 19.85, Machine Learning 18.38, SQL 13.97 and Big Data 8.82. The <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">pie<\/code> function already draws a circle, so you do not need an extra axis equal line.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Scatter Plot in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">A scatter plot draws one dot for each pair of values. It shows whether two variables move together, and where the odd points sit. A third variable can set the colour or the size of the dots. Keep in mind that a pattern shows a link, not a cause.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\ngirls_marks = [19, 30, 10, 69, 80, 60, 14, 30, 80, 34]\r\nboys_marks = [90, 29, 49, 48, 100, 48, 38, 45, 20, 30]\r\ngrades_range = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\r\nfig = plt.figure()\r\nax = fig.add_axes([0.1, 0.1, 0.8, 0.8])\r\nax.scatter(grades_range, girls_marks, color=\"r\", label=\"girls\")\r\nax.scatter(grades_range, boys_marks, color=\"b\", label=\"boys\")\r\nax.set_xlabel(\"Grades Range\")\r\nax.set_ylabel(\"Grades Scored\")\r\nax.set_title(\"scatter plot\")\r\nax.legend()\r\nplt.show()<\/pre>\n<\/div>\n<p style=\"margin: 0 0 16px;\"><img loading=\"lazy\" decoding=\"async\" style=\"display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid #d9e0ea; border-radius: 8px;\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/scatter.png\" alt=\"Scatter plot of girls marks in red and boys marks in blue against grade range\" width=\"850\" height=\"638\" \/><\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">label<\/code> and <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">legend<\/code> lines tell the reader which colour is which. Without them, red and blue would be a guess.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Contour Plot in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">A contour plot shows a surface on a flat page. It is sometimes called a level plot. You give it a grid of X and Y values, and a height Z for each point. X goes on the x axis and Y on the y axis, and Z is shown by lines or colours. The function <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">contour<\/code> draws lines, and <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">contourf<\/code> fills the bands with colour.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nxlist = np.linspace(-8.0, 10.0, 100)\r\nylist = np.linspace(-8.0, 10.0, 100)\r\nX, Y = np.meshgrid(xlist, ylist)\r\nZ = np.sqrt(X ** 4 + Y ** 4)\r\nfig, ax = plt.subplots(1, 1)\r\ncp = ax.contourf(X, Y, Z)\r\nfig.colorbar(cp)  # add a colorbar to the plot\r\nax.set_title(\"Filled Contours Plot\")\r\nax.set_xlabel(\"x (cm)\")\r\nax.set_ylabel(\"y (cm)\")\r\nplt.show()<\/pre>\n<\/div>\n<p style=\"margin: 0 0 16px;\"><img loading=\"lazy\" decoding=\"async\" style=\"display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid #d9e0ea; border-radius: 8px;\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Contour.png\" alt=\"Filled contour plot with a colour bar, titled Filled Contours Plot\" width=\"850\" height=\"638\" \/><\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Quiver Plot in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">A quiver plot draws arrows. Each arrow sits at a point and has a direction and a length. It is used for wind, water flow, forces and slopes. These are its parameters.<\/p>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 520px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Quiver plot parameters<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 140px;\" scope=\"col\">Parameter<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">What it sets<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">x, y<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">The position of each arrow<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">u, v<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">The horizontal and vertical size of each arrow<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; font-family: 'Courier New',Courier,monospace; font-size: 15px; white-space: nowrap;\" scope=\"row\">c<\/th>\n<td style=\"padding: 12px 16px;\">An optional colour for each arrow<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">In the code below, <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">np.gradient<\/code> gives the slope of the surface. It takes the spacing along y first, then x. The y grid steps by 0.25 and the x grid by 0.2, so the call is <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">np.gradient(z, .25, .2)<\/code>.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nx, y = np.meshgrid(np.arange(-2, 2, .2), np.arange(-2, 2, .25))\r\nz = x * np.exp(-x ** 2 - y ** 2)\r\nv, u = np.gradient(z, .25, .2)  # spacing along y first, then x\r\nfig, ax = plt.subplots()\r\nq = ax.quiver(x, y, u, v)\r\nplt.show()<\/pre>\n<\/div>\n<p style=\"margin: 0 0 16px;\"><img loading=\"lazy\" decoding=\"async\" style=\"display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid #d9e0ea; border-radius: 8px;\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Quiver.png\" alt=\"Quiver plot of arrows pointing uphill toward the peak of a surface\" width=\"850\" height=\"638\" \/><\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The arrows point uphill, toward the peak on the right and away from the dip on the left. They are longest where the slope is steepest.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Box Plot in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">A box plot summarises a set of numbers with five values: the lowest value in range, the first quartile, the median, the third quartile and the highest value in range. The box runs from the first to the third quartile, and the line inside it is the median. By default the whiskers reach 1.5 times the interquartile range, and any point beyond that is drawn as a separate circle and called an outlier.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nvalue1 = [82, 76, 24, 40, 67, 62, 71, 79, 81, 22, 98, 89, 78, 67, 72, 82, 87, 66, 56, 52]\r\nvalue2 = [12, 25, 11, 35, 36, 32, 96, 95, 3, 90, 95, 32, 27, 55, 100, 12, 1, 451, 37, 21]\r\nvalue3 = [23, 89, 12, 78, 72, 89, 25, 69, 68, 86, 19, 49, 15, 16, 16, 75, 65, 31, 25, 52]\r\nvalue4 = [99, 33, 75, 66, 83, 61, 82, 98, 10, 87, 29, 72, 26, 23, 72, 88, 78, 99, 75, 30]\r\nbox_plot_data = [value1, value2, value3, value4]\r\nplt.boxplot(box_plot_data)\r\nplt.show()<\/pre>\n<\/div>\n<p style=\"margin: 0 0 16px;\"><img loading=\"lazy\" decoding=\"async\" style=\"display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid #d9e0ea; border-radius: 8px;\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/box1.png\" alt=\"Box plot of four data sets, with one far outlier above the second box\" width=\"850\" height=\"638\" \/><\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">You will see four boxes. The second data set has a circle far above the others at 451. It is an outlier, and it also squashes the other boxes into the bottom of the chart. The first data set shows two outliers near 22 and 24, drawn so close that they look like one.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Violin Plot in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">A violin plot has the same summary idea as a box plot, and adds the shape of the density on each side. The wide parts of the shape show where most values sit. It shows more than a box plot, but it is also harder to read for a new audience, so the choice depends on who reads it. Remember that a box plot shows the median, and not the mean.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nnp.random.seed(10)\r\ncollectn_1 = np.random.normal(300, 30, 300)\r\ncollectn_2 = np.random.normal(60, 10, 300)\r\ncollectn_3 = np.random.normal(60, 40, 300)\r\ncollectn_4 = np.random.normal(20, 25, 300)\r\n# combine these different collections into a list\r\ndata_to_plot = [collectn_1, collectn_2, collectn_3, collectn_4]\r\nfig = plt.figure()\r\nax = fig.add_axes([0.1, 0.1, 0.8, 0.8])\r\nvp = ax.violinplot(data_to_plot, showmedians=True)\r\nplt.show()<\/pre>\n<\/div>\n<p style=\"margin: 0 0 16px;\"><img loading=\"lazy\" decoding=\"async\" style=\"display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid #d9e0ea; border-radius: 8px;\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/voilen.png\" alt=\"Violin plot of four data sets with a median line in each\" width=\"850\" height=\"638\" \/><\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The first violin sits high, around 300. The second is short, because its values vary the least. The third is the tallest, because its values vary the most. The <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">showmedians<\/code> argument adds a line at the median of each one.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Three Dimensional Plotting in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Although Matplotlib began as a 2D library, it can draw 3D plots through the mplot3d toolkit. To create a 3D axes, set <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">projection<\/code> to the text <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">\"3d\"<\/code>. In recent versions the import of mplot3d is no longer needed, but it does no harm. The first 3D example draws a line that spirals upward.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nfig = plt.figure()\r\nax = plt.axes(projection=\"3d\")\r\nz = np.linspace(0, 2, 200)\r\nx = z * np.sin(40 * z)\r\ny = z * np.cos(40 * z)\r\nax.plot3D(x, y, z, \"red\")\r\nax.set_title(\"3D line plot\")\r\nplt.show()<\/pre>\n<\/div>\n<p style=\"margin: 0 0 16px;\"><img loading=\"lazy\" decoding=\"async\" style=\"display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid #d9e0ea; border-radius: 8px;\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/3ds.png\" alt=\"3D line plot, a red spiral rising upward\" width=\"850\" height=\"638\" \/><\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">3D Contour Plot<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">contour3D<\/code> method draws contour lines on a 3D surface, given a grid of X and Y values and the height Z. The number 50 is how many levels to draw, and <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">cmap<\/code> sets the colours.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\ndef f(x, y):\r\n    return np.sin(np.sqrt(x ** 2 + y ** 2))\r\n\r\nx = np.linspace(-4, 4, 40)\r\ny = np.linspace(-4, 4, 40)\r\nX, Y = np.meshgrid(x, y)\r\nZ = f(X, Y)\r\nfig = plt.figure()\r\nax = plt.axes(projection=\"3d\")\r\nax.contour3D(X, Y, Z, 50, cmap=\"binary\")\r\nax.set_xlabel(\"x\")\r\nax.set_ylabel(\"y\")\r\nax.set_zlabel(\"z\")\r\nax.set_title(\"3D contour\")\r\nplt.show()<\/pre>\n<\/div>\n<p style=\"margin: 0 0 16px;\"><img loading=\"lazy\" decoding=\"async\" style=\"display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid #d9e0ea; border-radius: 8px;\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/counter-1.png\" alt=\"3D contour plot of ripples drawn in grey\" width=\"850\" height=\"638\" \/><\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">3D Wireframe Plot<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">plot_wireframe<\/code> method places a mesh of lines over the surface, so you see the shape without a solid fill. It uses the same X, Y and Z grids as the contour above. They are repeated here so the code runs on its own, and only the last calls change.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nx = np.linspace(-4, 4, 40)\r\ny = np.linspace(-4, 4, 40)\r\nX, Y = np.meshgrid(x, y)\r\nZ = np.sin(np.sqrt(X ** 2 + Y ** 2))\r\nfig = plt.figure()\r\nax = plt.axes(projection=\"3d\")\r\nax.plot_wireframe(X, Y, Z, color=\"green\")\r\nax.set_title(\"wireframe\")\r\nplt.show()<\/pre>\n<\/div>\n<p style=\"margin: 0 0 16px;\"><img loading=\"lazy\" decoding=\"async\" style=\"display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid #d9e0ea; border-radius: 8px;\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/wired-1.png\" alt=\"3D wireframe plot, a green net over a rippled surface\" width=\"850\" height=\"638\" \/><\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">3D Surface Plot in Matplotlib<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">plot_surface<\/code> method draws a filled 3D surface. It takes the X, Y and Z grids, and the surface is coloured by height when you pass a colour map. In this example Z is the dependent value, calculated from X and Y.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nx = np.outer(np.linspace(-4, 4, 40), np.ones(40))\r\ny = x.copy().T  # transpose\r\nz = np.cos(x ** 2 + y ** 2)\r\nfig = plt.figure()\r\nax = plt.axes(projection=\"3d\")\r\nax.plot_surface(x, y, z, cmap=\"viridis\", edgecolor=\"none\")\r\nax.set_title(\"Surface plot\")\r\nplt.show()<\/pre>\n<\/div>\n<p style=\"margin: 0 0 16px;\"><img loading=\"lazy\" decoding=\"async\" style=\"display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid #d9e0ea; border-radius: 8px;\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/sureface-1.png\" alt=\"3D surface plot coloured by height with the viridis colour map\" width=\"640\" height=\"480\" \/><\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">np.outer<\/code> call builds a grid where every row is the same, and the transpose makes a matching grid in the other direction. Together they work like <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">meshgrid<\/code>.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Which Plot Should You Use?<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Pick the plot by the question you want the chart to answer.<\/p>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 640px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Choosing a plot<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">If you want to show<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Use<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Function<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">A trend over time<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Line plot<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">plot<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">A comparison across categories<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Bar plot<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">bar, barh<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">How one set of numbers is spread<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Histogram, box plot or violin plot<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">hist, boxplot, violinplot<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Parts of a whole, five or fewer<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Pie chart<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">pie<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">The link between two numbers<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Scatter plot<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">scatter<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">A surface on a flat page<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Contour plot<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">contour, contourf<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">Direction and size at many points<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">Quiver plot<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0;\">quiver<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; white-space: nowrap;\" scope=\"row\">A surface in three dimensions<\/th>\n<td style=\"padding: 12px 16px;\">Wireframe or surface plot<\/td>\n<td style=\"padding: 12px 16px;\">plot_wireframe, plot_surface<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Common Mistakes With Matplotlib<\/h2>\n<ul style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px; padding-left: 24px;\">\n<li style=\"margin: 0 0 8px;\"><strong>Curly quotes in code.<\/strong> Text copied from a web page or a Word file can turn straight quotes into curly ones, and Python rejects them.<\/li>\n<li style=\"margin: 0 0 8px;\"><strong>A stray character before import.<\/strong> One minus sign at the start of a line stops the whole program.<\/li>\n<li style=\"margin: 0 0 8px;\"><strong>Misspelt method names.<\/strong> The correct names are <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">set_xticklabels<\/code> and not <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">set_xlabels<\/code>, and <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">xlabel<\/code> and not <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">xlable<\/code>.<\/li>\n<li style=\"margin: 0 0 8px;\"><strong>An axis that cuts off the data.<\/strong> Check the axis range after you set ticks, as in the stacked bar example.<\/li>\n<li style=\"margin: 0 0 8px;\"><strong>Overlapping titles.<\/strong> Call <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">tight_layout<\/code> when you use more than one plot.<\/li>\n<li style=\"margin: 0 0 8px;\"><strong>No labels or legend.<\/strong> If a chart has two colours and no legend, the reader has to guess.<\/li>\n<li style=\"margin: 0 0 8px;\"><strong>Reading too much into a scatter plot.<\/strong> A pattern shows a link, not a cause.<\/li>\n<\/ul>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Complete Script to Run Yourself<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Here is the full script used to test every plot on this page. It saves each plot as an image in a folder called <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">viz_out<\/code>, so create that folder first. The line <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">matplotlib.use(\"Agg\")<\/code> lets it run without opening windows. Remove it if you want to see the plots on screen.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import math\r\nimport matplotlib\r\nmatplotlib.use(\"Agg\")  # lets the script run without a window; remove this line in Jupyter\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\nfrom mpl_toolkits import mplot3d  # not needed in recent versions, kept for older ones\r\n \r\nprint(matplotlib.__version__, np.__version__)\r\n \r\n# Image functions: imsave, imread, imshow\r\npixels = np.array([[0.0, 0.5, 1.0], [1.0, 0.5, 0.0], [0.0, 1.0, 0.0]])\r\nplt.imsave(\"viz_out\/tiny.png\", pixels, cmap=\"gray\")\r\nimg = plt.imread(\"viz_out\/tiny.png\")\r\nprint(img.shape)\r\nfig, ax = plt.subplots()\r\nax.imshow(img)\r\nfig.savefig(\"viz_out\/00_imshow.png\")\r\nplt.close(fig)\r\n \r\n# Figure class\r\ng1 = plt.figure(figsize=(6, 3), dpi=100, facecolor=\"lightgrey\", edgecolor=\"navy\", linewidth=2)\r\nprint(g1.get_size_inches(), g1.dpi)\r\nplt.close(g1)\r\n \r\n# axes.plot with format strings\r\ny = [1, 5, 10, 17, 25, 36, 49, 64]\r\nx1 = [1, 16, 30, 42, 55, 68, 77, 88]\r\nx2 = [1, 6, 12, 18, 28, 40, 52, 65]\r\nfig = plt.figure()\r\nax = fig.add_axes([0.1, 0.1, 0.8, 0.8])\r\nl1 = ax.plot(x1, y, \"rs-\")    # red, square markers, solid line\r\nl2 = ax.plot(x2, y, \"mo--\")   # magenta, circle markers, dashed line\r\nax.legend(labels=(\"Hadoop\", \"Data science\"), loc=\"lower right\")\r\nax.set_title(\"Learners enrolled over time\")\r\nax.set_xlabel(\"Learners enrolled\")\r\nax.set_ylabel(\"Weeks since launch\")\r\nfig.savefig(\"viz_out\/01_plot.png\")\r\nplt.close(fig)\r\n \r\n# Multiplot: subplots(2, 2)\r\nfig, a = plt.subplots(2, 2)\r\nx = np.arange(2, 8)\r\na[0][0].plot(x, x ** 2)\r\na[0][0].set_title(\"square\")\r\na[0][1].plot(x, np.sqrt(x))\r\na[0][1].set_title(\"square root\")\r\na[1][0].plot(x, np.exp(x))\r\na[1][0].set_title(\"exp\")\r\na[1][1].plot(x, np.log10(x))\r\na[1][1].set_title(\"log\")\r\nfig.tight_layout()\r\nfig.savefig(\"viz_out\/02_subplots.png\")\r\nplt.close(fig)\r\n \r\n# subplot2grid\r\na1 = plt.subplot2grid((4, 4), (0, 0), colspan=2)\r\na2 = plt.subplot2grid((4, 4), (0, 2), rowspan=3)\r\na3 = plt.subplot2grid((4, 4), (1, 0), rowspan=2, colspan=2)\r\nx = np.arange(1, 10)\r\na2.plot(x, x ** 3)\r\na2.set_title(\"cube\")\r\na1.plot(x, np.exp(x))\r\na1.set_title(\"exp\")\r\na3.plot(x, np.log(x))\r\na3.set_title(\"log\")\r\nplt.tight_layout()\r\nplt.savefig(\"viz_out\/03_grid2.png\")\r\nplt.close()\r\n \r\n# grid()\r\nfig, axes = plt.subplots(1, 3, figsize=(12, 4))\r\nx = np.arange(2, 22)\r\naxes[0].plot(x, x ** 4, \"g\", lw=2)\r\naxes[0].grid(True)\r\naxes[0].set_title(\"default grid\")\r\naxes[1].plot(x, np.exp(x), \"r\")\r\naxes[1].grid(color=\"b\", ls=\"-.\", lw=0.25)\r\naxes[1].set_title(\"custom grid\")\r\naxes[2].plot(x, x)\r\naxes[2].set_title(\"no grid\")\r\nfig.tight_layout()\r\nfig.savefig(\"viz_out\/04_grid.png\")\r\nplt.close(fig)\r\n \r\n# Limits\r\nfig = plt.figure()\r\na1 = fig.add_axes([0.1, 0.1, 0.8, 0.8])\r\nx = np.arange(1, 90)\r\na1.plot(x, np.exp(x), \"r\")\r\na1.set_title(\"exp\")\r\na1.set_ylim(0, 80000)\r\na1.set_xlim(0, 10)\r\nfig.savefig(\"viz_out\/05_limits.png\")\r\nplt.close(fig)\r\n \r\n# Ticks and tick labels\r\nx = np.arange(0, math.pi * 4, 0.04)\r\nfig = plt.figure()\r\nax = fig.add_axes([0.1, 0.1, 0.8, 0.8])\r\nax.plot(x, np.sin(x))\r\nax.set_xlabel(\"angle\")\r\nax.set_title(\"sine\")\r\nax.set_xticks([0, 3, 6, 9])\r\nax.set_xticklabels([\"a\", \"b\", \"c\", \"d\"])\r\nax.set_yticks([-1, 0, 1])\r\nfig.savefig(\"viz_out\/06_ticks.png\")\r\nplt.close(fig)\r\n \r\n# Bar plot, stacked and side by side\r\nN = 5\r\nboysMeans = (120, 135, 130, 135, 127)\r\ngirlsMeans = (125, 132, 134, 120, 125)\r\nind = np.arange(N)\r\nwidth = 0.35\r\nfig = plt.figure()\r\nax = fig.add_axes([0.1, 0.1, 0.8, 0.8])\r\nax.bar(ind, boysMeans, width, color=\"r\")\r\nax.bar(ind, girlsMeans, width, bottom=boysMeans, color=\"b\")\r\nax.set_ylabel(\"Scores\")\r\nax.set_title(\"Scores by group and gender (stacked)\")\r\nax.set_xticks(ind, (\"G1\", \"G2\", \"G3\", \"G4\", \"G5\"))\r\nax.set_yticks(np.arange(0, 301, 50))\r\nax.legend(labels=[\"boys\", \"girls\"])\r\nfig.savefig(\"viz_out\/07_bar_stacked.png\")\r\nplt.close(fig)\r\n \r\nfig, ax = plt.subplots()\r\nax.bar(ind - width \/ 2, boysMeans, width, color=\"r\", label=\"boys\")\r\nax.bar(ind + width \/ 2, girlsMeans, width, color=\"b\", label=\"girls\")\r\nax.set_ylabel(\"Scores\")\r\nax.set_title(\"Scores by group and gender (side by side)\")\r\nax.set_xticks(ind, (\"G1\", \"G2\", \"G3\", \"G4\", \"G5\"))\r\nax.legend()\r\nfig.savefig(\"viz_out\/07_bar_side.png\")\r\nplt.close(fig)\r\n \r\n# Histogram\r\nfig, ax = plt.subplots(1, 1)\r\na = np.array([22, 87, 5, 43, 56, 73, 55, 54, 11, 20, 51, 5, 79, 31, 27])\r\ncounts, edges, patches = ax.hist(a, bins=[0, 25, 50, 75, 100])\r\nprint(counts, edges)\r\nax.set_title(\"histogram of result\")\r\nax.set_xticks([0, 25, 50, 75, 100])\r\nax.set_xlabel(\"marks\")\r\nax.set_ylabel(\"no. of students\")\r\nfig.savefig(\"viz_out\/08_hist.png\")\r\nplt.close(fig)\r\n \r\n# Pie chart\r\nfig = plt.figure()\r\nax = fig.add_axes([0.1, 0.1, 0.8, 0.8])\r\nlangs = [\"Statistics\", \"Python\", \"Machine Learning\", \"SQL\", \"Big Data\"]\r\nstudents = [53, 27, 25, 19, 12]\r\nax.pie(students, labels=langs, autopct=\"%1.2f%%\")\r\nfig.savefig(\"viz_out\/09_pie.png\")\r\nplt.close(fig)\r\n \r\n# Scatter plot\r\ngirls_marks = [19, 30, 10, 69, 80, 60, 14, 30, 80, 34]\r\nboys_marks = [90, 29, 49, 48, 100, 48, 38, 45, 20, 30]\r\ngrades_range = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]\r\nfig = plt.figure()\r\nax = fig.add_axes([0.1, 0.1, 0.8, 0.8])\r\nax.scatter(grades_range, girls_marks, color=\"r\", label=\"girls\")\r\nax.scatter(grades_range, boys_marks, color=\"b\", label=\"boys\")\r\nax.set_xlabel(\"Grades Range\")\r\nax.set_ylabel(\"Grades Scored\")\r\nax.set_title(\"scatter plot\")\r\nax.legend()\r\nfig.savefig(\"viz_out\/10_scatter.png\")\r\nplt.close(fig)\r\n \r\n# Contour plot\r\nxlist = np.linspace(-8.0, 10.0, 100)\r\nylist = np.linspace(-8.0, 10.0, 100)\r\nX, Y = np.meshgrid(xlist, ylist)\r\nZ = np.sqrt(X ** 4 + Y ** 4)\r\nfig, ax = plt.subplots(1, 1)\r\ncp = ax.contourf(X, Y, Z)\r\nfig.colorbar(cp)  # add a colorbar to the plot\r\nax.set_title(\"Filled Contours Plot\")\r\nax.set_xlabel(\"x (cm)\")\r\nax.set_ylabel(\"y (cm)\")\r\nfig.savefig(\"viz_out\/11_contour.png\")\r\nplt.close(fig)\r\n \r\n# Quiver plot\r\nx, y = np.meshgrid(np.arange(-2, 2, .2), np.arange(-2, 2, .25))\r\nz = x * np.exp(-x ** 2 - y ** 2)\r\nv, u = np.gradient(z, .25, .2)  # spacing along y first, then x\r\nfig, ax = plt.subplots()\r\nq = ax.quiver(x, y, u, v)\r\nfig.savefig(\"viz_out\/12_quiver.png\")\r\nplt.close(fig)\r\n \r\n# Box plot\r\nvalue1 = [82, 76, 24, 40, 67, 62, 71, 79, 81, 22, 98, 89, 78, 67, 72, 82, 87, 66, 56, 52]\r\nvalue2 = [12, 25, 11, 35, 36, 32, 96, 95, 3, 90, 95, 32, 27, 55, 100, 12, 1, 451, 37, 21]\r\nvalue3 = [23, 89, 12, 78, 72, 89, 25, 69, 68, 86, 19, 49, 15, 16, 16, 75, 65, 31, 25, 52]\r\nvalue4 = [99, 33, 75, 66, 83, 61, 82, 98, 10, 87, 29, 72, 26, 23, 72, 88, 78, 99, 75, 30]\r\nbox_plot_data = [value1, value2, value3, value4]\r\nfig, ax = plt.subplots()\r\nbp = ax.boxplot(box_plot_data)\r\nprint(\"outliers per box:\", [len(f.get_ydata()) for f in bp[\"fliers\"]])\r\nfig.savefig(\"viz_out\/13_box.png\")\r\nplt.close(fig)\r\n \r\n# Violin plot\r\nnp.random.seed(10)\r\ncollectn_1 = np.random.normal(300, 30, 300)\r\ncollectn_2 = np.random.normal(60, 10, 300)\r\ncollectn_3 = np.random.normal(60, 40, 300)\r\ncollectn_4 = np.random.normal(20, 25, 300)\r\ndata_to_plot = [collectn_1, collectn_2, collectn_3, collectn_4]\r\nfig = plt.figure()\r\nax = fig.add_axes([0.1, 0.1, 0.8, 0.8])\r\nvp = ax.violinplot(data_to_plot, showmedians=True)\r\nfig.savefig(\"viz_out\/14_violin.png\")\r\nplt.close(fig)\r\n \r\n# 3D line plot\r\nfig = plt.figure()\r\nax = plt.axes(projection=\"3d\")\r\nz = np.linspace(0, 2, 200)\r\nx = z * np.sin(40 * z)\r\ny = z * np.cos(40 * z)\r\nax.plot3D(x, y, z, \"red\")\r\nax.set_title(\"3D line plot\")\r\nfig.savefig(\"viz_out\/15_3dline.png\")\r\nplt.close(fig)\r\n \r\n# 3D contour, wireframe and surface share one function\r\ndef f(x, y):\r\n    return np.sin(np.sqrt(x ** 2 + y ** 2))\r\n \r\nx = np.linspace(-4, 4, 40)\r\ny = np.linspace(-4, 4, 40)\r\nX, Y = np.meshgrid(x, y)\r\nZ = f(X, Y)\r\n \r\nfig = plt.figure()\r\nax = plt.axes(projection=\"3d\")\r\nax.contour3D(X, Y, Z, 50, cmap=\"binary\")\r\nax.set_xlabel(\"x\")\r\nax.set_ylabel(\"y\")\r\nax.set_zlabel(\"z\")\r\nax.set_title(\"3D contour\")\r\nfig.savefig(\"viz_out\/16_contour3d.png\")\r\nplt.close(fig)\r\n \r\nfig = plt.figure()\r\nax = plt.axes(projection=\"3d\")\r\nax.plot_wireframe(X, Y, Z, color=\"green\")\r\nax.set_title(\"wireframe\")\r\nfig.savefig(\"viz_out\/17_wireframe.png\")\r\nplt.close(fig)\r\n \r\nx = np.outer(np.linspace(-4, 4, 40), np.ones(40))\r\ny = x.copy().T  # transpose\r\nz = np.cos(x ** 2 + y ** 2)\r\nfig = plt.figure()\r\nax = plt.axes(projection=\"3d\")\r\nax.plot_surface(x, y, z, cmap=\"viridis\", edgecolor=\"none\")\r\nax.set_title(\"Surface plot\")\r\nfig.savefig(\"viz_out\/18_surface.png\")\r\nplt.close(fig)\r\nprint(\"all plots saved\")<\/pre>\n<\/div>\n<p>Matplotlib has a lot of functions, but the ideas repeat. You make a figure, you add axes, you call one plot method, and you label it. Once you see that pattern, the 3D plots and the unusual charts become variations on the same steps. Run the script above, change the data, and break things on purpose. Then try a real dataset with pandas, and look at Seaborn when you want statistical charts with less code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Data Visualization in Python Using Matplotlib: Complete Tutorial Imagine you have a spreadsheet with ten thousand rows of sales, marks or sensor readings. You could scroll through it for hours and still miss the one pattern that matters. Draw a chart and you see it in seconds. Data visualization is the habit of turning numbers [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3333,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,1676],"tags":[385,71,541,544,546,542],"class_list":["post-2716","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-python-data-visualization","tag-data-visualization-in-python-using-matplotlib-tutorial","tag-data-visualization-with-matplotlib","tag-online-python-course-for-beginners","tag-online-python-course-with-certificate","tag-online-python-programming-course","tag-online-python-training-course"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Data Visualization in Python With Matplotlib Tutorial | Prwatech<\/title>\n<meta name=\"description\" content=\"A working Matplotlib reference: line, bar, histogram, pie, scatter, contour, box, violin and 3D plots, with corrected code you can copy and run.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Data Visualization in Python With Matplotlib Tutorial | Prwatech\" \/>\n<meta property=\"og:description\" content=\"A working Matplotlib reference: line, bar, histogram, pie, scatter, contour, box, violin and 3D plots, with corrected code you can copy and run.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Prwatech\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prwatech.in\/\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-19T04:48:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-20T06:11:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Data-Visualization-With-MatPlotLib.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"960\" \/>\n\t<meta property=\"og:image:height\" content=\"550\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Prwatech\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:site\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prwatech\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"17 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/\",\"url\":\"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/\",\"name\":\"Data Visualization in Python With Matplotlib Tutorial | Prwatech\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Data-Visualization-With-MatPlotLib.jpg\",\"datePublished\":\"2026-10-19T04:48:54+00:00\",\"dateModified\":\"2026-10-20T06:11:32+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"A working Matplotlib reference: line, bar, histogram, pie, scatter, contour, box, violin and 3D plots, with corrected code you can copy and run.\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#primaryimage\",\"url\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Data-Visualization-With-MatPlotLib.jpg\",\"contentUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Data-Visualization-With-MatPlotLib.jpg\",\"width\":960,\"height\":550,\"caption\":\"Data Visualization With MatPlotLib\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Data visualization\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/prwatech.in\/blog\/#website\",\"url\":\"https:\/\/prwatech.in\/blog\/\",\"name\":\"Prwatech\",\"description\":\"Share Ideas, Start Something Good.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/prwatech.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\",\"name\":\"Prwatech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"caption\":\"Prwatech\"},\"url\":\"https:\/\/prwatech.in\/blog\/author\/prwatech123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Data Visualization in Python With Matplotlib Tutorial | Prwatech","description":"A working Matplotlib reference: line, bar, histogram, pie, scatter, contour, box, violin and 3D plots, with corrected code you can copy and run.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Data Visualization in Python With Matplotlib Tutorial | Prwatech","og_description":"A working Matplotlib reference: line, bar, histogram, pie, scatter, contour, box, violin and 3D plots, with corrected code you can copy and run.","og_url":"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2026-10-19T04:48:54+00:00","article_modified_time":"2026-10-20T06:11:32+00:00","og_image":[{"width":960,"height":550,"url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Data-Visualization-With-MatPlotLib.jpg","type":"image\/jpeg"}],"author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"17 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/","url":"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/","name":"Data Visualization in Python With Matplotlib Tutorial | Prwatech","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Data-Visualization-With-MatPlotLib.jpg","datePublished":"2026-10-19T04:48:54+00:00","dateModified":"2026-10-20T06:11:32+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"A working Matplotlib reference: line, bar, histogram, pie, scatter, contour, box, violin and 3D plots, with corrected code you can copy and run.","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#primaryimage","url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Data-Visualization-With-MatPlotLib.jpg","contentUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Data-Visualization-With-MatPlotLib.jpg","width":960,"height":550,"caption":"Data Visualization With MatPlotLib"},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Data visualization"}]},{"@type":"WebSite","@id":"https:\/\/prwatech.in\/blog\/#website","url":"https:\/\/prwatech.in\/blog\/","name":"Prwatech","description":"Share Ideas, Start Something Good.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/prwatech.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3","name":"Prwatech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","caption":"Prwatech"},"url":"https:\/\/prwatech.in\/blog\/author\/prwatech123\/"}]}},"_links":{"self":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/2716","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/comments?post=2716"}],"version-history":[{"count":21,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/2716\/revisions"}],"predecessor-version":[{"id":12050,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/2716\/revisions\/12050"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media\/3333"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=2716"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=2716"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=2716"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}