Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

1,016 Articles Published

Articles by Rishikesh Kumar Rishi

Page 71 of 102

Pandas timeseries plot setting X-axis major and minor ticks and labels

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 536 Views

When working with Pandas time series data, you often need to customize the X-axis ticks and labels for better visualization. This involves setting both major and minor ticks to display dates at appropriate intervals. Steps Create a random number generator with a fixed seed for reproducible results. Generate a fixed frequency DatetimeIndex using pd.date_range() from '2020-01-01' to '2021-01-01'. Create sample data using a mathematical function or random distribution. Build a DataFrame with the time series data. Create a plot with custom figure size and configure major/minor ticks. Display the plot using plt.show(). Basic Time Series ...

Read More

What's the fastest way of checking if a point is inside a polygon in Python?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 5K+ Views

Checking if a point is inside a polygon is a common computational geometry problem. Python offers several approaches, with matplotlib's Path class being one of the fastest and most reliable methods for this task. Using matplotlib.path for Point-in-Polygon Testing The matplotlib library provides an efficient implementation through the mplPath.Path class, which uses optimized algorithms for point-in-polygon testing. Steps Create a list of points to define the polygon vertices. Create a path object using mplPath.Path() with the polygon coordinates. Use the contains_point() method to check if a point lies inside the polygon. Example ...

Read More

How to plot ROC curve in Python?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 7K+ Views

The ROC (Receiver Operating Characteristic) curve is a graphical plot used to evaluate binary classification models. It shows the trade-off between true positive rate (sensitivity) and false positive rate (1-specificity) at various threshold settings. Python's sklearn.metrics module provides the plot_roc_curve() method to easily visualize ROC curves for classification models. Steps to Plot ROC Curve Generate a random binary classification dataset using make_classification() method Split the data into training and testing sets using train_test_split() method Train a classifier (like SVM) on the training data using fit() method Plot the ROC curve using plot_roc_curve() method Display the plot ...

Read More

How to make several plots on a single page using matplotlib in Python?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 513 Views

Matplotlib provides several methods to create multiple plots on a single page. You can use subplots() to create a grid of subplots or subplot() to add plots one by one. This is useful for comparing different datasets or showing related visualizations together. Method 1: Using subplots() with Multiple Axes The subplots() function creates a figure with multiple subplot areas in a grid layout − import matplotlib.pyplot as plt import numpy as np # Sample data x = np.linspace(0, 10, 100) y1 = np.sin(x) y2 = np.cos(x) y3 = np.tan(x) y4 = np.log(x + 1) ...

Read More

Scatter plot and Color mapping in Python

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 874 Views

We can create scatter plots with color mapping using Matplotlib's scatter() method. This technique allows us to visualize an additional dimension of data through color variations, making patterns and relationships more apparent. Basic Scatter Plot with Color Mapping Here's how to create a scatter plot where each point has a different color based on its position in the dataset − import matplotlib.pyplot as plt import numpy as np # Generate random data points x = np.random.rand(100) y = np.random.rand(100) # Create scatter plot with color mapping colors = range(100) plt.scatter(x, y, c=colors, cmap='viridis') plt.colorbar() ...

Read More

How to maximize a plt.show() window using Python?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 5K+ Views

To maximize a matplotlib plot window, you can use the figure manager's built-in methods. The most common approach is using plt.get_current_fig_manager() along with full_screen_toggle() or window.state() methods. Method 1: Using full_screen_toggle() This method toggles the window to full screen mode ? import matplotlib.pyplot as plt plt.subplot(1, 1, 1) plt.pie([1, 2, 3], labels=['A', 'B', 'C']) plt.title('Sample Pie Chart') mng = plt.get_current_fig_manager() mng.full_screen_toggle() plt.show() Method 2: Using window.state() (Tkinter backend) For Tkinter backend, you can maximize the window using the state method ? import matplotlib.pyplot as plt plt.subplot(1, 1, 1) ...

Read More

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

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 32K+ Views

When creating data visualizations, you often need to display multiple plots side-by-side for comparison. Python's Matplotlib provides the subplot() method to divide a figure into multiple sections and place plots in specific positions. Using plt.subplot() Method The subplot(nrows, ncols, index) method splits a figure into a grid of nrows × ncols sections. The index parameter specifies which section to use for the current plot ? from matplotlib import pyplot as plt import numpy as np # Create sample data x_points = np.array([2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) y1_points = np.array([12, 14, ...

Read More

Saving images in Python at a very high quality

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 9K+ Views

To save images in Python with very high quality, you need to control the image format and resolution. The most effective approach is using matplotlib's savefig() method with optimized parameters. Steps for High-Quality Image Saving Create fig and ax variables using subplots() method, where default nrows and ncols are 1. Plot the data using plot() method. Add axes labels using ylabel() and xlabel(). Use vector formats like .eps, .pdf, or .svg for scalable quality. Increase the DPI (dots per inch) value for ...

Read More

How to iterate over rows in a DataFrame in Pandas?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 420 Views

To iterate rows in a DataFrame in Pandas, we can use the iterrows() method, which will iterate over DataFrame rows as (index, Series) pairs.StepsCreate a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.Iterate df using df.iterrows() method.Print each row with index.Exampleimport pandas as pd df = pd.DataFrame(    {       "x": [5, 2, 1, 9],       "y": [4, 1, 5, 10],       "z": [4, 1, 5, 0]    } ) print "Given DataFrame:", df for index, row in df.iterrows():    print "Row ", index, "contains: "    print row["x"], row["y"], row["z"]OutputGiven DataFrame:    x   y   z 0  5   4   4 1  2   1   1 2  1   5   5 3  9  10   0 Row 0 contains: 5 4 4 Row 1 contains: 2 1 1 Row 2 contains: 1 5 5 Row 3 contains: 9 10 0

Read More

Select rows from a Pandas DataFrame based on column values

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 1K+ Views

To select rows from a DataFrame based on column values, we can take the following Steps −Create a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.Print the input DataFrame.Use df.loc[df["x"]==2] to print the DataFrame when x==2.Similarly, print the DataFrame when (x >= 2) and (x < 2).Exampleimport pandas as pd df = pd.DataFrame(    {       "x": [5, 2, 1, 9],       "y": [4, 1, 5, 10],       "z": [4, 1, 5, 0]    } ) print "Given DataFrame is:", df print "When column x value == 2:", df.loc[df["x"] == 2] ...

Read More
Showing 701–710 of 1,016 articles
« Prev 1 69 70 71 72 73 102 Next »
Advertisements