Rishikesh Kumar Rishi has Published 1156 Articles

Extract csv file specific columns to list in Python

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:45:13

16K+ Views

To extract csv file for specific columns to list in Python, we can use Pandas read_csv() method.StepsMake a list of columns that have to be extracted.Use read_csv() method to extract the csv file into data frame.Print the exracted data.Plot the data frame using plot() method.To display the figure, use show() method.Exampleimport pandas as ... Read More

How to make a log histogram in Python?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:44:51

4K+ Views

To make a log histogram, we can use log=True in the argument of the hist() method.StepsMake a list of numbers.Plot a histogram with density=True.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True k = np.array([5, 5, 5, 5]) x, bins, ... Read More

How to shade the regions between the curves in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:44:30

6K+ Views

To shade the regions between curves, we can use the fill_between() method.StepsInitialize the variable n. Initiliize x and y data points using numpy.Create a figure and a set of subplots, fig and ax.Plot the curve using plot method.Use fill_between() method, fill the area between the two curves.To display the figure, use show() method.Exampleimport numpy as np ... Read More

Line plot with arrows in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:44:09

5K+ Views

To plot with arrows in matplotlib, we can use arrow() method.StepsCreate x and y data points using numpy.Plot x and y with color=red and linewidth = 1.Use arrow method to add an arrow to the axes. The first two values in the arguments are the coordinates of the arrow base ... Read More

How to center an annotation horizontally over a point in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:43:18

1K+ Views

To center an annotation horizontally over a point, we can take the following steps−Create points for x and y using numpy.Create labels using xpoints.Use scatter() method to scatter the points.Iterate labels, xpoints and ypoints and annotate the plot with label, x and y with different properties, make horizontal alignment ha=center.To ... Read More

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

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

4K+ 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

1K+ 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

11K+ 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

2K+ 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

Advertisements