Rishikesh Kumar Rishi has Published 1162 Articles

Plotting dates on the X-axis with Python's Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 28-Aug-2023 12:43:55

26K+ Views

Using Pandas, we can create a dataframe and can set the index for datetime. Using gcf().autofmt_xdate(), we will adjust the date on the X-axis.StepsMake the list of date_time and convert into it in date_time using pd.to_datetime().Consider data = [1, 2, 3]Instantiate DataFrame() object, i.e., DF.Set the DF['value'] with data from ... Read More

Python Pandas – Find the maximum value of a column and return its corresponding row values

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 27-Aug-2023 13:31:30

25K+ Views

To find the maximum value of a column and to return its corresponding row values in Pandas, we can use df.loc[df[col].idxmax()]. Let's take an example to understand it better.StepsCreate a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.Print the input DataFrame, df.Initialize a variable, col, to find the maximum value of ... Read More

How to make two plots side-by-side using Python?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 27-Aug-2023 03:24:13

27K+ Views

Using subplot(row, col, index) method, we can split a figure in row*col parts, and can plot the figure at the index position. In the following program, we will create two diagrams in a single figure.StepsCreating x, y1, y2 points using numpy.With nrows = 1, ncols = 2, index = 1, ... Read More

How to plot CSV data using Matplotlib and Pandas in Python?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 26-Aug-2023 03:10:30

37K+ Views

To plot CSV data using Matplotlib and Pandas in Python, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a list of headers of the .CSV file.Read the CSV file with headers.Set the index and plot the dataframe.To display the ... Read More

How to label a line in Matplotlib (Python)?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 25-Aug-2023 01:59:00

39K+ 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 ... Read More

How to plot an array in Python using Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 25-Aug-2023 00:24:57

44K+ 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 ... Read More

How to plot a function defined with def in Python? (Matplotlib)

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 24-Aug-2023 16:23:56

52K+ Views

To plot a function defined with def in Python, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a user-defined function using, def, i.e., f(x).Create x data points using numpy.Plot x and f(x) using plot() method.To display the figure, use ... Read More

How to import Matplotlib in Python?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 23-Aug-2023 14:11:54

63K+ Views

First of all, make sure you have python and pip preinstalled on your system. To check Python version, typepython --versionTo check pip version, typepip −VThen, run the following pip command in the command prompt to install Matplotlib.pip install matplotlibTo verify that matplotlib is successfully installed on your system, execute the ... Read More

How can I plot a single point in Matplotlib Python?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 23-Aug-2023 14:04:08

59K+ Views

To plot a single data point in matplotlib, we can take the following steps −Initialize a list for x and y with a single value.Limit X and Y axis range for 0 to 5.Lay out a grid in the current line style.Plot x and y using plot() method with marker="o", ... Read More

How to set X-axis values in Matplotlib Python?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 22-Aug-2023 16:04:36

71K+ Views

To set X-axis values in matplotlib in Python, we can take the following steps −Create two lists for x and y data points.Get the xticks range value.Plot a line using plot() method with xtick range value and y data points.Replace xticks with X-axis value using xticks() method.To display the figure, use show() method.Examplefrom matplotlib import ... Read More

Advertisements