Articles on Trending Technologies

Technical articles with clear explanations and examples

Manually add legend Items Python Matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 17-Mar-2021 23K+ Views

Using plt.legend() method, we can create a legend, and passing frameon would help to keep the border over there.StepsSet the X-axis label using plt.xlabel() method.Set the Y-axis label using plt.ylabel() method.Draw lines using plot() method.Location and legend drawn flags can help to find a location and make the flag True for the border.Set the legend with “blue” and “orange” elements.To show the figure use plt.show() method.Exampleimport matplotlib.pyplot as plt plt.ylabel("Y-axis ") plt.xlabel("X-axis ") plt.plot([9, 5], [2, 5], [4, 7, 8]) location = 0 # For the best location legend_drawn_flag = True plt.legend(["blue", "orange"], loc=0, frameon=legend_drawn_flag) plt.show()Output

Read More

Show only certain items in legend Python Matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 17-Mar-2021 2K+ Views

Using plt.legend(), we can add or show certain items just by putting the values in the list.StepsSet the X-axis label using plt.xlabel() method.Set the Y-axis label using plt.ylabel() method.Plot the lines using the lists that are passed in the plot() method argument.Location and legend_drawn flags can help to find a location and make the flag True for border.Set the legend with “blue” and “orange” elements.To show the figure use plt.show() method.Exampleimport matplotlib.pyplot as plt plt.ylabel("Y-axis ") plt.xlabel("X-axis ") plt.plot([9, 5], [2, 5], [4, 7, 8]) location = 0 # For the best location legend_drawn_flag = True plt.legend(["blue", ...

Read More

Blurring an image using the OpenCV function blur()

Prasad Naik
Prasad Naik
Updated on 17-Mar-2021 467 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.

Read More

How to test for significant relationship between two categorical columns of an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2021 716 Views

To test for the significance of proportion between two categorical columns of an R data frame, we first need to find the contingency table using those columns and then apply the chi square test for independence using chisq.test. For example, if we have a data frame called df that contains two categorical columns say C1 and C2 then the test for significant relationship can be done by using the command chisq.test(table(df$C1,df$C2))Example Live Demox1

Read More

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

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 17-Mar-2021 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

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2021 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

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2021 271 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

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2021 380 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

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2021 1K+ 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

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2021 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

Read More
Showing 33051–33060 of 61,248 articles
Advertisements