Articles on Trending Technologies

Technical articles with clear explanations and examples

How to change the scale of imshow in matplotlib without stretching the image?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 18K+ Views

To change the scale of imshow in matplotlib without stretching the image, you need to control the aspect ratio and extent parameters. This prevents distortion when displaying 2D data arrays as images. Understanding the Problem By default, matplotlib's imshow() automatically adjusts the image to fill the plot area, which can stretch or compress your data. The aspect and extent parameters give you precise control over scaling. Basic Example with Aspect Control Here's how to display an image without stretching using the aspect parameter ? import numpy as np import matplotlib.pyplot as plt # ...

Read More

Plotting profile histograms in Python Matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 858 Views

A profile histogram displays the mean value of y for each bin of x values, making it useful for visualizing relationships between variables. Python provides several approaches to create profile histograms using Matplotlib and Seaborn. Using Seaborn regplot() The regplot() method from Seaborn can create profile histograms by binning x values and showing mean y values ? import numpy as np import seaborn as sns import matplotlib.pyplot as plt # Set figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Generate sample data x = np.random.uniform(-5, 5, 1000) y = np.random.normal(x**2, np.abs(x) + ...

Read More

How to use ax.get_ylim() in matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 757 Views

The ax.get_ylim() method in matplotlib returns the current y-axis limits as a tuple containing the minimum and maximum values. This is useful for understanding the current scale of your plot or for programmatically adjusting other plot elements based on the y-axis range. Syntax ax.get_ylim() Return Value Returns a tuple (ymin, ymax) representing the current y-axis limits. Basic Example Here's how to use ax.get_ylim() to retrieve the y-axis limits ? import numpy as np import matplotlib.pyplot as plt # Set figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True ...

Read More

AngularJS – isUndefined() method

Mayank Agarwal
Mayank Agarwal
Updated on 26-Mar-2026 592 Views

The isUndefined() method in AngularJS checks if a reference is undefined or not. This method returns true if the reference passed to the function is undefined, otherwise it returns false. Syntax angular.isUndefined(value) Parameters value − The reference to check for undefined status Return Value Returns true if the value is undefined, false otherwise. Example − Check if References are Undefined Create an HTML file in your project directory and copy the following code ? ...

Read More

AngularJS – forEach() function

Mayank Agarwal
Mayank Agarwal
Updated on 26-Mar-2026 5K+ Views

The forEach() function in AngularJS uses an iterator to iterate over collections of items, objects, or arrays. The iterator function is called with three parameters: value, key, and obj. value represents the object property or array element key specifies the object property key or array element index obj represents the whole object reference Note that the forEach() function does not iterate over inherited properties. Syntax angular.forEach(obj, iterator, [context]) Parameters obj − The object or array to iterate over iterator − The function to be called for each item context ...

Read More

Program to find largest color value in a directed graph in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 438 Views

Suppose we have a directed graph with n colored nodes and m different edges. The nodes are numbered from 0 to n-1. We have a string col with lowercase letters, where col[i] represents the color of the ith node in this graph (0-indexed). We also have an edge list where edges[j] = (u, v) represents there is an edge between u and v. A valid path in the graph is a sequence of nodes xi for all i from 1 to k, such that there is a directed edge from xi to xi+1. The color value of the path ...

Read More

Program to find minimum interval to include each query in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 513 Views

Given a list of intervals and queries, we need to find the smallest interval that contains each query value. For each query, we return the size of the smallest interval that contains it, or -1 if no such interval exists. Problem Understanding Each interval is represented as [left, right] where both endpoints are inclusive. For a query value q, we need to find the interval with minimum size where left ≤ q ≤ right. The size of an interval [left, right] is right - left + 1. Example If the input is intervals = [[2, 5], ...

Read More

Program to find closest room from queries in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 326 Views

Given an array of rooms where rooms[i] = [roomId_i, size_i] and an array of queries where queries[j] = [preferred_j, minSize_j], we need to find the closest room for each query based on specific criteria. For each query, we need to find a room that: Has size of at least minSize_j |roomId - preferred_j| is minimized In case of tie, choose the room with smallest id Return -1 if no such room exists Example If rooms = [[2, 2], [1, 2], [3, 2]] and queries = [[3, 1], [3, 3], [5, 2]], the output is ...

Read More

Program to find maximum building height in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 997 Views

Suppose we have a value n and another list of pairs called restrictions. We want to build n new buildings in a city with specific constraints. Buildings are placed in a line and labeled from 1 to n. Each restriction has the format restrictions[i] = (id_i, max_height_i), indicating that building id_i must have height less than or equal to max_height_i. The city has the following height restrictions − The height of each building must be 0 or positive values. First building height must be 0. ...

Read More

Program to find XOR sum of all pairs bitwise AND in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 2K+ Views

Suppose we have two arrays arr1 and arr2. The XOR sum of a list is the bitwise XOR of all its elements. If the list has only one element, then its XOR sum will be the element itself. Now, consider a list containing the result of arr1[i] AND arr2[j] (bitwise AND) for every index pair (i, j) where 0 ≤ i < length of arr1 and 0 ≤ j < length of arr2. We have to find the XOR sum of that list. So, if the input is like arr1 = [5, 3, 4] and arr2 = [2, 6], ...

Read More
Showing 3271–3280 of 61,299 articles
« Prev 1 326 327 328 329 330 6130 Next »
Advertisements