Rishikesh Kumar Rishi has Published 1162 Articles

How to rotate xticklabels in Matplotlib so that the spacing between each xticklabel is equal?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

349 Views

To rotate xticklabels in matplotlib to make equal spacing between two xticklabels, we can take the following steps −Make a list of numbers from 1 to 4.Using subplot(), sdd a subplot to the current figure.Add xticks and yticks on the current subplot (using step 1).Set xtick labels by passing a list and to make ... Read More

Colorplot of 2D array in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:00:44

1K+ Views

To plot a colorplot of a 2D array, we can take the following steps −Create data (i.e., 2D array) using numpy.For colorplot, use imshow() method, with input data (Step 1) and colormap is "PuBuGn".To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = ... Read More

Adding caption below X-axis for a scatter plot using Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

4K+ Views

To add caption below X-axis for a scatter plot, we can use text() method for the current figure.StepsCreate x and y data points using numpy.Create a new figure or activate an existing figure using figure() method.Plot the scatter points with x and y data points.To add caption to the figure, ... Read More

How to plot a confusion matrix with string axis rather than integer in Python?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 12:54:44

509 Views

To plot a confusion matrix with string axis rather than integer in Python, we can take the following steps−Make a list for labels.Create a confusion matrix. Use confusion_matrix() to calculate accuracy of classification.3. Add an '~.axes.Axes' to the figure as part of a subplot arrangement.Plot the values of a 2D ... Read More

How can I hide the axes in Matplotlib 3D?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 12:54:18

1K+ Views

To hide the axes in matplotlib 3D, we can take the following steps−Create a 2D array, where x, y, z, u, v and w are the coordinates of the arrow locations and direction components of the arrow vectors.Using figure() method, create a new figure or activate an existing figure.Add an ... Read More

Set variable point size in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 12:53:39

323 Views

To set the variable point size in matplotlib, we can take the following steps−Initialize the coordinates of the point.Make a variable to store the point size.Plot the point using scatter method, with marker=o, color=red, s=point_size.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] ... Read More

How to draw a rectangle over a specific region in a Matplotlib graph?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 12:52:30

533 Views

To draw a rectangle over a specific region in a matplotlib graph, we can take the following steps −Using subplots() method, create a figure and a set of subplots, where nrows=1.Using rectangle, we can create a rectangle, defined via an anchor point and its width and height. Where, edgecolor=orange, linewidth=7, and facecolor=green.To ... Read More

How to create a draggable legend in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 12:52:08

1K+ Views

To create a draggable legend in matplotlib, we can take the following steps −Create two lines, line1 and line2, using plot() method.Place the legend for plot line1 and line2 with ordered lables at location 1, using legend() method.To create a draggable legend, use set_draggable() method, where state=True. If state=False, then we can't drag ... Read More

Automatically Rescale ylim and xlim in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 12:51:49

2K+ Views

To rescale ylim and xlim automatically, we can take the following steps −To plot a line, use plot() method and data range from 0 to 10.To scale the xlim and ylim automatically, we can make the variable scale_factore=6.Use scale_factor (from Step 2) to rescale the xlim and ylim, using xlim() and ylim() methods, respectively.To display the figure, use ... Read More

How do I plot Shapely polygons and objects using Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 12:51:12

6K+ Views

To plot shapely polygons and objects using matplotlib, the steps are as follows −Create a polygon object using (x, y) data points.Get x and y, the exterior data, and the array using polygon.exterior.xy.Plot x and y data points using plot() method with red color.Examplefrom shapely.geometry import Polygon import matplotlib.pyplot as plt ... Read More

Advertisements