Found 26504 Articles for Server Side Programming

How to turn on minor ticks only on the y-axis Matplotlib?

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

2K+ Views

First, we can create fig, ax using subplots() and then, we can plot the lines. After that, using ax.yaxis.set_minor_locator(tck.AutoMinorLocator()), we can turn on the minor ticks.StepsCreate fig and ax variables using subplots method, where default nrows and ncols are 1.Plot the line using two lists.Set the locator of the minor ticker.Dynamically find minor tick positions based on the positions of major ticks. The scale must be linear with major ticks evenly spaced.Using plt.show() method, we can show the figure.Exampleimport matplotlib.pyplot as plt import matplotlib.ticker as tck fig, ax = plt.subplots() plt.plot([0, 2, 4], [3, 6, 1]) ax.yaxis.set_minor_locator(tck.AutoMinorLocator()) plt.show()OutputRead More

How to replace a particular value in R data frame with a new value?

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

1K+ Views

To replace a particular value in R data frame with a new value, we can use ifelse function where the new value will be placed after the condition and if the column values do not match the condition then the same column will be placed. For example, if we have a data frame called df that contains a column x having 20 values and some of them are 5 and if we want to replace 5 with 2 then we can use the command df$x

Blurring an image using the OpenCV function Gaussian Blur()

Prasad Naik
Updated on 17-Mar-2021 07:50:47

556 Views

In this program, will blur an image using the openCV function GaussianBlur(). Gaussian blur is the process of blurring an image using the gaussian function. It is widely used in graphics software to remove noise from the image and reduce detail.AlgorithmStep 1: Import cv2. Step 2: Read the original image. Step 3: Apply gaussian blur function. Pass the image and the kernel size as parameter. Step 4: Display the image.Original ImageExample Codeimport cv2 image = cv2.imread("testimage.jpg") Gaussian = cv2.GaussianBlur(image, (7,7), 0) cv2.imshow("Gaussian Blur", Gaussian)OutputGaussian Blur:

Blurring an image using the OpenCV function blur()

Prasad Naik
Updated on 17-Mar-2021 07:50:10

417 Views

In this program, we will blur an image using the opencv function blur().AlgorithmStep 1: Import OpenCV. Step 2: Import the image. Step 3: Set the kernel size. Step 4: Call the blur() function and pass the image and kernel size as parameters. Step 5: Display the results.Original ImageExample Codeimport cv2 image = cv2.imread("testimage.jpg") kernel_size = (7,7) image = cv2.blur(image, kernel_size) cv2.imshow("blur", image)OutputBlurred ImageExplanationThe kernel size is used to blur only a small part of an image. The kernel moves across the entire image and blurs the pixels it covers.

Display text on an OpenCV window by using the function putText()

Prasad Naik
Updated on 17-Mar-2021 07:49:09

5K+ Views

In this program, we will write text on an image using the opencv function putText(). This function takes in the image, font, coordinates of where to put the text, color, thickness, etc.Original ImageAlgorithmStep 1: Import cv2 Step 2: Define the parameters for the puttext( ) function. Step 3: Pass the parameters in to the puttext() function. Step 4: Display the image.Example Codeimport cv2 image = cv2.imread("testimage.jpg") text = "TutorialsPoint" coordinates = (100,100) font = cv2.FONT_HERSHEY_SIMPLEX fontScale = 1 color = (255,0,255) thickness = 2 image = cv2.putText(image, text, coordinates, font, fontScale, color, thickness, cv2.LINE_AA) cv2.imshow("Text", image)Output

How to create boxplot in base R with higher width of the box lines?

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

236 Views

To create boxplot in base R with higher width of the box lines, we can use the boxlwd argument inside boxplot function. For example, if we have a vector called x then we can create the boxplot with higher width of the box lines using the command −boxplot(x,boxlwd=5)Example Live Demox

How to add a second X-axis in Matplotlib?

Rishikesh Kumar Rishi
Updated on 17-Mar-2021 07:48:18

12K+ Views

We can use the twiny() method to create a second X-axis. Similarly, using twinx, we can create a shared Y-axis.StepsCreate fig and ax variables using subplots method, where default nrows and ncols are 1.Plot line with lists passed in the argument of plot() method with color="red".Create a twin of Axes with a shared Y-axis but independent X-axis.Plot the line on ax2 that is created in step 3.Adjust the padding between and around subplots.To show the figure, use plt.show() method.Exampleimport matplotlib.pyplot as plt fig, ax1 = plt.subplots() ax1.plot([1, 2, 3, 4, 5], [3, 5, 7, 1, 9], color='red') ax2 = ax1.twiny() ... Read More

What does .shape[] do in “for i in range(Y.shape[0])” using Matplotlib?

Rishikesh Kumar Rishi
Updated on 17-Mar-2021 07:45:39

1K+ Views

The shape property is usually used to get the current shape of an array, but it may also be used to reshape the array in-place by assigning a tuple of array dimensions to it.StepsGet an array Y using np.array method.Y.shape would return a tuple (4, ).Y.shape[0] method would return 4, i.e., the first element of the tuple.Exampleimport numpy as np Y = np.array([1, 2, 3, 4]) print("Output of .show method would be: ", Y.shape, " for ", Y) print("Output of .show[0] method would be: ", Y.shape[0], " for ", Y) print("Output for i in range(Y.shape[0]): ", end=" ") for ... Read More

Multiple axes in Matplotlib with different scales

Rishikesh Kumar Rishi
Updated on 17-Mar-2021 07:55:01

4K+ Views

In the following code, we will see how to create a shared Y-axis.StepsCreate fig and ax variables using subplots method, where default nrows and ncols are 1.Plot line with lists passed in the argument of plot() method with color="red".Create a twin of Axes with a shared X-axis but independent Y-axis.Plot the line on ax2 that is created in step 3.Adjust the padding between and around subplots.To show the figure use plt.show() method.Exampleimport matplotlib.pyplot as plt fig, ax1 = plt.subplots() ax1.plot([1, 2, 3, 4, 5], [3, 5, 7, 1, 9], color='red') ax2 = ax1.twinx() ax2.plot([11, 12, 31, 41, 15], [13, 51, ... Read More

How to find the fractional power of a negative number in R?

Nizamuddin Siddiqui
Updated on 17-Mar-2021 07:35:04

315 Views

To find the fractional power of a negative number, we can find the power separately for the numerator and denominator where denominator will have the numerator 1. For example, if we have a vector called x that contains a single value -10 then the fractional power 15/7 of x can be found by using the command ((x)^15)^(1/7)Example Live Demox1

Advertisements