
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 26504 Articles for Server Side Programming

286 Views
In this program, we will crop an image using the Pillow library. We will use the crop() function for the same. The function takes left, top, right, bottom pixel coordinates to crop the image.Original ImageAlgorithmStep 1: Import Image from Pillow. Step 2: Read the image. Step 3: Crop the image using the crop function. Step 4: Display the output.Example Codefrom PIL import Image im = Image.open('testimage.jpg') width, height = im.size left = 5 top = height / 2 right = 164 bottom = 3 * height / 2 im1 = im.crop((left, top, right, bottom)) im1.show()Output

215 Views
In this program, we will read or load an image using the pillow library. The pillow library consists of a method called Image.open(). This function takes the file path or the name of the file as a string. To display the image, we use another function show(). It does not require any parameter.Example Codefrom PIL import Image im = Image.open('testimage.jpg') im.show()Output

6K+ Views
First, we can make two lists of x and y, where the values will be more than 1000. Then, we can use the ax.yaxis.set_major_formatter method where can pass StrMethodFormatter('{x:, }') method with {x:, } formatter that helps to separate out the 1000 figures from the given set of numbers.StepsMake two lists having numbers greater than 2000.Create fig and ax variables using subplots method, where default nrows and ncols are 1, using subplot() method.Plot line using x and y (from step 1).Set the formatter of the major ticker, using ax.yaxis.set_major_formatter() method, where StrMethodFormatter helps to make 1000 with common, i.e., expression ... Read More

14K+ Views
First, we can create a scatter for different data points using the scatter method, and then, we can plot the lines using the plot method.StepsCreate a new figure, or activate an existing figure with figure size(4, 3), using figure() method.Add an axis to the current figure and make it the current axes, create x using plt.axes().Draw scatter points using scatter() method.Draw line using ax.plot() method.Set the X-axis label using plt.xlabel() method.Set the Y-axis label using plt.ylabel() method.To show the plot, use plt.show() method.Exampleimport random import matplotlib.pyplot as plt plt.figure(figsize=(4, 3)) ax = plt.axes() ax.scatter([random.randint(1, 1000) % 50 for i ... Read More

10K+ Views
First, we can calculate the mean and standard deviation of the input data using Pandas dataframe.Then, we could plot the data using Matplotlib.StepsCreate a list and store it in data.Using Pandas, create a data frame with data (step 1), mean, std.Plot using a dataframe.To show the figure, use plt.show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt data = [-5, 1, 8, 7, 2] df = pd.DataFrame({ 'data': data, 'mean': [2.6 for i in range(len(data))], 'std': [4.673328578 for i in range(len(data))]}) df.plot() plt.show()Output

1K+ Views
Matplotlib can wrap text automatically, but if it's too long, the text will be displayed slightly outside of the boundaries of the axis anyways.StepsCreate a new figure, or activate an existing figure, using figure().Set the axis properties using plt.axis() method.Make a variable input_text to store the string.Add text to figure, using plt.text() method where style='oblique', ha='center', va='top', ...etc.To show the figure use plt.show() method.Exampleimport matplotlib.pyplot as plt fig = plt.figure() plt.axis([0, 10, 0, 10]) input_text = 'Matplotlib is a plotting library for the Python programming language and its numerical mathematics extension NumPy.' plt.text(5, 5, input_text, fontsize=10, style='oblique', ha='center', va='top', ... Read More

9K+ Views
First, we can create bars using plt.bar and using xticks. Then, we can align the labels by setting the “vertical” or “horizontal” attributes in the “rotation” key.StepsMake lists, bars_heights, and bars_label, with numbers.Make a bar plot using bar() method, with bars_heights and length of bars_label.Get or set the current tick locations and labels of the X-axis, using xticks() with rotation='vertical' and bars_label.To show the plot, use plt.show() method.Examplefrom matplotlib import pyplot as plt bars_heights = [14, 8, 10] bars_label = ["A label", "B label", "C label"] plt.bar(range(len(bars_label)), bars_heights) plt.xticks(range(len(bars_label)), bars_label, rotation='vertical') plt.show()OutputRead More

3K+ Views
By creating a 3D projection on the axis and iterating that axis for different angles using view_init(), we can rotate the output diagram.StepsCreate a new figure, or activate an existing figure.Add an `~.axes.Axes` to the figure as part of a subplot arrangement with nrow = 1, ncols = 1, index = 1, and projection = '3d'.Use the method, get_test_data to return a tuple X, Y, Z with a test dataset.Plot a 3D wireframe with data test data x, y, and z.To make it rotatable, we can set the elevation and azimuth of the axes in degrees (not radians), using view_init() ... Read More

779 Views
In this program, we will detect contours in an image. Contours can be explained simply as a curve joining all the continuous points having the same color or intensity. The contours are a useful tool for shape analysis and object detection and recognition.Original ImageAlgorithmStep 1: Import OpenCV. Step 2: Import matplotlib. Step 3: Read the image. Step 4: Convert the image from bgr2rgb. Step 5: Convert the rgb image to grayscale. Step 4: Perform thresholding on the image. Step 5: Find contours on the image. Step 6: Draw contours on the image. Step 7: Display the output.Example Codeimport cv2 import ... Read More

2K+ Views
In this program, we will find the edges in an image using the pillow library. The FIND_EDGES function in the ImageFilter class helps us to find the edges in our image.Original ImageAlgorithmStep 1: Import Image and ImageFilter from Pillow. Step 2: Open the image. Step 3: Call the filter function and specify the find_edges function. Step 4: Display the output.Example Codefrom PIL import Image, ImageFilter im = Image.open('testimage.jpg') im = im.filter(ImageFilter.FIND_EDGES) im.show()Output