Rishikesh Kumar Rishi has Published 1162 Articles

How to draw axis in the middle of a figure in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:27:41

3K+ Views

To draw axis in the middle of a figure, we can take the following steps −Create x and sqr data points using numpy.Create a new figure, or activate an existing figure, using figure() method.Add an axis to the figure as a part of a subplot arrangement.Set the postion of left and bottom ... Read More

What does a 4-element tuple argument for 'bbox_to_anchor' mean in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:27:08

387 Views

If a 4-tuple or B box Base is given, then it specifies the b box (x, y, width, height) that the legend is placed in.StepsCreate x and y data points using numpy.Plot x and y using plot() method, with label y=sin(x) and color=green.To place the legend at a specific location, ... Read More

How to make the angles in a Matplotlib polar plot go clockwise with 0° at the top?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:26:43

4K+ Views

To make the angles in a matplotlib polar plot go clockwise with 00 at the top, we can take the followingsteps−StepsAdd a subplot to the current figure ax.To set polar plot clockwise with top 0o, set the theta direction as −1 using set_theta_direction()method. And, use set_theta_offset() method to set the ... Read More

Matplotlib – Plot over an image background in Python

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:26:18

18K+ Views

To plot over an image background, we can take the following steps−Read an image from a file into an array.Create a figure (fig) and add a set of subplots (ax) with extent [0, 300, 0, 300].Create an array x of range (300).Plot x using plot() method with linestyle=dotted, linewidth=2, and ... Read More

Equivalent to matlab's imagesc in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:25:54

3K+ Views

To make equivalent imagesc, we can use extent [left, right, bottom, top].StepsCreate random data using numpy.Display the data as an image, i.e., on a 2D regular raster, with data and extent [−1, 1, −1, 1] arguments.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as ... Read More

Shading an area between two points in a Matplotlib plot

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:25:29

6K+ Views

To shade an area between two points in matplotlib, we can take the following steps−Create x and y data points using numpy.Plot x and y data points, with color=red and linewidth=2.To shade an area parallel to X-axis, initialize two variables, y1 and y2.To add horizontal span across the axes, use ... Read More

Creating a graph with date and time in axis labels with Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:25:04

3K+ Views

To create a graph with date and time in axis labels, we can take the following steps−Create a figure and add a set of subplots.Create x and y data points using numpy.Set date formatter for X-axis.Plot x and y using plot() method.Set the ticks of X-axis.Set the date-time tick labels ... Read More

How to specify values on Y-axis in Python Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:24:32

11K+ Views

To specify values on Y-axis in Python, we can take the following steps−Create x and y data points using numpy.To specify the value of axes, create a list of characters.Use xticks and yticks method to specify the ticks on the axes with x and y ticks data points respectively.Plot the ... Read More

How to plot 1D data at a given Y-value with PyLab using Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:24:09

3K+ Views

To plot 1D data at a given Y-value with pyplot, we can take the following steps−Initialize y value.Create x and y data points using numpy. zeros_like helps to return an array of zeros with the same shape and type as a given array and add y-value for y data points.Plot ... Read More

Matplotlib – How to insert a degree symbol into a Python plot?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:19:02

9K+ Views

To insert a degree symbol into a plot, we can use LaTeX representation.StepsCreate data points for pV, nR and T using numpy.Plot pV and T using plot() method.Set xlabel for pV using xlabel() method.Set the label for temperature with degree symbol using ylabel() method.To display the figure, use show() method.Exampleimport ... Read More

Advertisements