Label a Line in Matplotlib Python

Rishikesh Kumar Rishi
Updated on 25-Aug-2023 01:59:00

51K+ Views

To label a line in matplotlib, we can use label in the argument of plot() method,StepsSet the figure size and adjust the padding between and around the subplots.Plot with label="line1" using plot() method.Plot with label="line2" using plot() method.To place a legend on the figure, use legend() method.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True line1, = plt.plot([1, 2, 3], label="line1") line2, = plt.plot([3, 2, 1], label="line2") leg = plt.legend(loc='upper center') plt.show()Output

Convert Date and Time with Different Timezones in Python

Vikram Chiluka
Updated on 25-Aug-2023 01:57:04

54K+ Views

In this article, we will show you how to convert date and time with different timezones in Python. Using astimezone() function Using datetime.now() function The easiest way in Python date and time to handle timezones is to use the pytz module. This library allows accurate and cross−platform timezone calculations. pytz brings the Olson tz database into Python. It also solves the issue of ambiguous times at the end of daylight saving time, which you can read more about in the Python Library Reference (datetime.tzinfo) Before you use it you'll need to install it using − pip install pytz ... Read More

Mask an Image in OpenCV Python

Shahid Akhtar Khan
Updated on 25-Aug-2023 01:20:28

53K+ Views

We can apply a mask to an image by computing the cv2.bitwise_and() between the mask and the image. To track a color, we define a mask in HSV color space using cv2.inRange() passing lower and upper limits of color values in HSV.Also Read: Color Identification in Images using Python and OpenCV To track a part of the image we can define a mask using np.zeros() and slicing the entries with white (255) for the region in the input image to examine. Follow the given steps to mask an image − The first step is to import required libraries. The ... Read More

Create DataFrame in Python

pawandeep
Updated on 25-Aug-2023 01:13:12

34K+ Views

Dataframe is a 2D data structure. Dataframe is used to represent data in tabular format in rows and columns. It is like a spreadsheet or a sql table. Dataframe is a Pandas object.To create a dataframe, we need to import pandas. Dataframe can be created using dataframe() function. The dataframe() takes one or two parameters. The first one is the data which is to be filled in the dataframe table. The data can be in form of list of lists or dictionary of lists. In case of list of lists data, the second parameter is the columns name.Create dataframe from ... Read More

Calculate Number of Days Between Two Dates Using Python

Pranav Indukuri
Updated on 25-Aug-2023 01:08:03

34K+ Views

In this article we will discuss how to find the number of days between two dates using Python. We use the datetime module to calculate the number of days between two dates using python. datetime module Python has a built-in datetime module that assists us in resolving a number of date-related issues. We just input the two dates with the date type and subtract them to discover the difference between the two dates, which gives us the number of days between the two dates. Syntax The syntax of the date() method in datetime module is as follows. datetime.date(year, month, day) ... Read More

Add Character to Specific Position in String Using Python

Vikram Chiluka
Updated on 25-Aug-2023 00:51:31

67K+ Views

In this article, we will learn how to add a character to a specific position in a string in Python. Methods Used The following are the various methods to accomplish this task − Using the '+' operator Using join() function Using format() function Method 1: Using the '+' operator We can concatenate strings and characters using the symbol "+" at the required positions. Adding Character at the End of a String Algorithm: Following are the Algorithms/steps to be followed to perform the desired task. − Create a variable to store an input string. Use the "+" operator ... Read More

What is Negative Indexing in Python

AmitDiwan
Updated on 25-Aug-2023 00:33:24

41K+ Views

Negative Indexing is used to in Python to begin slicing from the end of the string i.e. the last. Slicing in Python gets a sub-string from a string. The slicing range is set as parameters i.e. start, stop, and step. Syntax Let us see the syntax − #slicing from index start to index stop-1 arr[start:stop] # slicing from index start to the end arr[start:] # slicing from the beginning to index stop - 1 arr[:stop] # slicing from the index start to index stop, by skipping step arr[start:stop:step] If the values above are in negative, that ... Read More

Plot an Array in Python Using Matplotlib

Rishikesh Kumar Rishi
Updated on 25-Aug-2023 00:24:57

59K+ Views

To plot an array in Python, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create two arrays, x and y, using numpy.Set the title of the curve using title() method.Plot x and y data points, with red color.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 x = np.array([5, 4, 1, 4, 5]) y = np.sort(x) plt.title("Line graph") plt.plot(x, y, color="red") plt.show()Output

Find Client IP Address in Python

Pradeep Elance
Updated on 25-Aug-2023 00:22:01

60K+ Views

In this tutorial, we are going to find the IP address of the client using the socket module in Python. Every laptop, mobile, tablet, etc.., have their unique IP address. We will find it by using the socket module. Let's see the steps to find out the IP address of a device.Algorithm Import the socket module. Get the hostname using the socket.gethostname() method and store it in a variable. Find the IP address by passing the hostname as an argument to the socket.gethostbyname() method and store it in a variable. Print the IP address. Let's write code for the above ... Read More

Change User Password in Ubuntu

Satish Kumar
Updated on 24-Aug-2023 20:47:16

3K+ Views

Introduction If you are a Linux user, there is no doubt that you have heard of Ubuntu OS. Ubuntu is an open-source operating system based on the Debian architecture and is one of the most popular distributions of Linux. It's user-friendly interface, and versatile nature makes it a great operating system for both personal and professional use. As with any operating system, password security in Ubuntu is of utmost importance. With cyberattacks increasing day by day, secure passwords are essential to keep your information safe from unauthorized access. This guide aims to simplify the process of changing your user password ... Read More

Advertisements