Found 26504 Articles for Server Side Programming

Make 3D plot interactive in Jupyter Notebook (Python & Matplotlib)

Rishikesh Kumar Rishi
Updated on 17-Mar-2021 07:58:03

3K+ Views

In this article, we can take a program code to show how we can make a 3D plot interactive using Jupyter Notebook.StepsCreate a new figure, or activate an existing figure.Create fig and ax variables using subplots method, where default nrows and ncols are 1, projection=’3d”.Get x, y and z using np.cos and np.sin function.Plot the 3D wireframe, using x, y, z and color="red".Set a title to the current axis.To show the figure, use plt.show() method.Exampleimport matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = fig.add_subplot(111, projection='3d') u, v = np.mgrid[0:2 * np.pi:30j, 0:np.pi:20j] x = np.cos(u) * ... Read More

How do you plot a vertical line on a time series plot in Pandas?

Rishikesh Kumar Rishi
Updated on 17-Mar-2021 07:58:29

4K+ Views

Using Pandas, we will create a dataframe and set the vertical lines on the created axes, using axvline lines.StepsUsing panda we can create a data frame.Creating a data frame would help to create help.Using axvline(), add a vertical line across the axes, where color is green, linestyle="dashed".Using axvline(), add a vertical line across the axes, where color is red, linestyle="dashed".Using plt.show(), show the plot.Exampleimport pandas as pd from matplotlib import pyplot as plt df = pd.DataFrame(index=pd.date_range("2019-07-01", "2019-07-31")) df["y"] = 1 ax = df.plot() ax.axvline("2019-07-24", color="green", linestyle="dashed") ax.axvline("2019-07-31", color="red", linestyle="dashed") plt.show()OutputRead More

How to zoom subplots together in Matplotlib/Pyplot?

Rishikesh Kumar Rishi
Updated on 17-Mar-2021 08:01:02

3K+ Views

We can use the attribute sharex = "ax1", and then, use the subplot method to zoom the subplots together.StepsAdd a subplot to the current figure with (nrow = 1, ncols = 2, index = 1).Add line on the current subplot with (nrow = 1, ncols = 2, index = 1).Add a subplot to the current figure with (nrow = 1, ncols = 2, index = 2).Add line on the current subplot with (nrow = 1, ncols = 2, index = 2), where sharex can help to share the x or y `~matplotlib.axis` with sharex and/or sharey. The axis will have ... Read More

How to check if an R matrix column contains only duplicate values?

Nizamuddin Siddiqui
Updated on 17-Mar-2021 07:25:41

216 Views

To check if an R matrix column contains only duplicate values, we can use dim function for the dimension of the column after accessing the matrix column with table function. For example, if we have a matrix called M having five columns then we can check whether first column contains only duplicate values using the command dim(table(M[,1]))==1ExampleConsider the below data frame − Live DemoM1

How to write an image to a file using OpenCV?

Prasad Naik
Updated on 17-Mar-2021 07:59:02

490 Views

In this program, we will write an image or save an image to a file using OpenCV.AlgorithmStep 1: Import cv2 Step 2: Read the image using opencv.imread() Step 3: Save the image using opencv.imwrite(filename, image)Example Codeimport cv2 import os image = cv2.imread('testimage.jpg') directory = r'C:\Users\prasa\Desktop' os.chdir(directory) cv2.imwrite('CAMERAMAN.jpg', image)OutputThis program will save the image in the directory as same as the original image directoryExplanationEnsure that you have set the proper directory in order for the program to execute without errors.

Reading and displaying images using OpenCV

Prasad Naik
Updated on 17-Mar-2021 08:00:05

2K+ Views

In this article, we will learn how to read and display images using the OpenCV library.OpenCV is a library of programming functions mainly aimed at real time computer vision. Before reading an image, make sure that the image is in the same directory as your program.AlgorithmStep 1: Import OpenCV. Step 2: Read an image using imread(). Step 3: Display the image using imshow().Example Codeimport cv2 as cv image = cv.imread ('ronaldo.jpg') cv.imshow('Cristiano Ronaldo', image)Output

How to find the number of levels in R for a factor column?

Nizamuddin Siddiqui
Updated on 17-Mar-2021 07:21:09

942 Views

To find the number of levels in R for a factor column, we can use length function along with unique function. For example, if we have a data frame called df that contains a factor column X then we can find the number of levels in the factor column using the command −length(unique(df$X))ExampleConsider the below data frame − Live Demox1

How to replace space between two words with underscore in an R data frame column?

Nizamuddin Siddiqui
Updated on 17-Mar-2021 07:17:38

3K+ Views

To replace space between two words with underscore in an R data frame column, we can use gsub function. For example, if we have a data frame called df that contains character column x having two words having a single space between them then we can replace that space using the command df$x

How to find the standard deviation for rows in an R data frame?

Nizamuddin Siddiqui
Updated on 17-Mar-2021 07:11:49

919 Views

To find the standard deviation for rows in an R data frame, we can use mutate function of dplyr package and rowSds function of matrixStats package. For example, if we have a data frame called df that contains two columns x and y then we can find the standard deviation for rows using the below command −df%>%mutate(STDEV=rowSds(as.matrix(.[c("x","y")])))ExampleConsider the below data frame − Live Demox1

How to find the correlation between corresponding columns of two matrices in R?

Nizamuddin Siddiqui
Updated on 17-Mar-2021 07:05:10

856 Views

To find the correlation between corresponding columns of two matrices, we can use mapply function but we will have to read the matrices using as.data.frame function. For example, if we have two matrices called M_1 and M_2 and each of these matrices contains 5 columns then the correlation between corresponding columns of these matrices can be found by using the command mapply(cor,as.data.frame(M_1),as.data.frame(M_2))ExampleConsider the below matrices − Live DemoM1

Advertisements