Rishikesh Kumar Rishi has Published 1162 Articles

How to share secondary Y-axis between subplots in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:42:32

3K+ Views

To share secondary Y-axis between subplots in matplotlib, we can take the following steps −Create x for data points.Add a subplot to the current figure, with nrows=2, ncols=1, at index=1 (ax0)Using twinx() method, create a twin of axes with a shared X-axis but independent Y-axis (ax1).Add a subplot to the current ... Read More

How can I display an image using cv2 in Python?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:41:56

866 Views

To read an image in Python cv2, we can take the following steps−Load an image from a file.Display the image in the specified window.Wait for a pressed key.Destroy all of the HighGUI windows.Exampleimport cv2 img = cv2.imread("baseball.png", cv2.IMREAD_COLOR) cv2.imshow("baseball", img) cv2.waitKey(0) cv2.destroyAllWindows()OutputRead More

Rotate xtick labels in Seaborn boxplot using Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 14:01:12

10K+ Views

To rotate xtick labels in Seaborn boxplot, we can take the following steps −Create data points for xticks.Draw a boxplot using boxplot() method that returns the axis.Now, set the xticks using set_xticks() method, pass xticks.Set xticklabels and pass a list of labels and rotate them by passing rotation=45, using set_xticklabels() method.To display ... Read More

Extract Matplotlib colormap in hex-format

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

1K+ Views

To extract matplotlib colormap in hex-format, we can take the following steps −Get the rainbow color map.Iterate in the range of rainbow colormap length.Using rgb2hex method, convert rgba tuple to a hexadecimal representation of a color.Examplefrom matplotlib import cm import matplotlib cmap = cm.rainbow for i in range(cmap.N):    rgba ... Read More

How do you directly overlay a scatter plot on top of a jpg image in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

2K+ Views

To directly overlay a scatter plot on top of a jpg image, we can take the following steps −Load an image "bird.jpg", using imread() method, Read an image from a file into an array.Now display data as an image.To plot scatter points on the image make lists for x_points and ... Read More

Plot a histogram with Y-axis as percentage in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:57:06

2K+ Views

To plot a histogram with Y-axis as percentage in matplotlib, we can take the following steps −Create a list of numbers as y.Create a number of bins.Plot a histogram using hist() method, where y, bins, and edgecolor are passed in the argument.Store the patches to set the percentage on Y-axis.Create a list ... Read More

Setting Y-axis in Matplotlib using Pandas

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

5K+ Views

To set Y-Axis in matplotlib using Pandas, we can take the following steps −Create a dictionary with the keys, x and y.Create a data frame using Pandas.Plot data points using Pandas plot, with ylim(0, 25) and xlim(0, 15).To display the figure, use show() method.Exampleimport numpy as np import pandas as pd from ... Read More

How to remove the outline of a circle marker when using pyplot.plot in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:52:23

886 Views

To remove the outline of a circle marker, we can reduce the value of marker edge width.Initialize list for x and y, with a single value.Limit x and y axis range for 0 to 5.Lay out a grid in current line style.Plot the given x and y using plot() method, with marker="o", markeredgecolor="red", markerfacecolor="green" and ... Read More

How to use 'extent' in matplotlib.pyplot.imshow?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:51:59

2K+ Views

To use extent in matplotlib imshow(), 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 ... Read More

Python Matplotlib Venn diagram

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

2K+ Views

To plot a Venn diagram, first install Venn diagram using command "pip install matplotlib-venn". Using venn3, plot a 3-set area-weighted Venn diagram.StepsCreate 3 sets.Using venn3, make a Venn diagram.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt from matplotlib_venn import venn3 plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True set1 = {'A', ... Read More

Advertisements