How to exponentially scale the Y axis with matplotlib?

Rishikesh Kumar Rishi
Updated on 26-Mar-2026 13:18:18

5K+ Views

To exponentially scale the Y-axis with matplotlib, you can use the yscale() function with different scale types. The most common approach is using symlog (symmetric logarithmic) scaling, which handles both positive and negative values effectively. Basic Exponential Y-axis Scaling Here's how to create a plot with exponential Y-axis scaling ? 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 # Create data points dt = 0.01 x = np.arange(-50.0, 50.0, dt) y = np.arange(0, 100.0, dt) # Plot the data plt.plot(x, y) ... Read More

Python - Convert List of lists to List of Sets

AmitDiwan
Updated on 26-Mar-2026 13:17:59

905 Views

Converting a list of lists to a list of sets is useful for removing duplicates from each inner list while maintaining the outer structure. Python provides several approaches using map(), list comprehensions, and loops. Using map() Function The map() function applies the set() constructor to each inner list ? my_list = [[2, 2, 2, 2], [1, 2, 1], [1, 2, 3], [1, 1], [0]] print("The list of lists is:") print(my_list) my_result = list(map(set, my_list)) print("The resultant list is:") print(my_result) The list of lists is: [[2, 2, 2, 2], [1, 2, ... Read More

Python program to get all subsets having sum s

AmitDiwan
Updated on 26-Mar-2026 13:17:42

813 Views

When working with lists, you might need to find all subsets that sum to a specific value. Python's itertools.combinations provides an efficient way to generate all possible subsets and check their sums. Using itertools.combinations The combinations function generates all possible subsets of different sizes from the input list ? from itertools import combinations def find_subsets_with_sum(arr, target_sum): result = [] # Generate subsets of all possible sizes (0 to len(arr)) for size in range(len(arr) + 1): ... Read More

Python - Filter Rows Based on Column Values with query function in Pandas?

AmitDiwan
Updated on 26-Mar-2026 13:17:25

747 Views

To filter rows based on column values, we can use the query() function. In the function, set the condition through which you want to filter records. At first, import the required library − import pandas as pd Following is our data with Team Records − team = [['India', 1, 100], ['Australia', 2, 85], ['England', 3, 75], ['New Zealand', 4, 65], ['South Africa', 5, 50], ['Bangladesh', 6, 40]] Create a DataFrame from above and add columns as well − dataFrame = pd.DataFrame(team, ... Read More

Python - Find all the strings that are substrings to the given list of strings

AmitDiwan
Updated on 26-Mar-2026 13:17:08

670 Views

Finding strings that are substrings of other strings in a list is a common task in Python. We can use different approaches including list comprehensions with in operator and the any() function. Using List Comprehension with in Operator This approach checks if each string from one list appears as a substring in any string from another list ? main_strings = ["Hello", "there", "how", "are", "you"] search_strings = ["Hi", "there", "how", "have", "you", "been"] print("Main strings:", main_strings) print("Search strings:", search_strings) # Find strings from search_strings that are substrings of any string in main_strings result = ... Read More

Python program to print sorted number formed by merging all elements in array

AmitDiwan
Updated on 26-Mar-2026 13:16:51

303 Views

When it is required to print the sorted numbers that are formed by merging all elements in an array, we can use string manipulation and sorting techniques. The approach involves converting all numbers to strings, joining them together, sorting the digits, and converting back to an integer. Example Below is a demonstration of the same − def get_sorted_nums(my_num): my_num = ''.join(sorted(my_num)) my_num = int(my_num) print(my_num) def merged_list(my_list): my_list = list(map(str, my_list)) my_str = ''.join(my_list) ... Read More

Python Pandas – Can we use & Operator to find common columns between two DataFrames?

AmitDiwan
Updated on 26-Mar-2026 13:16:33

344 Views

Yes, we can use the & operator to find the common columns between two DataFrames. The & operator performs a set intersection operation on DataFrame column indexes, returning only the columns that exist in both DataFrames. Creating Two DataFrames Let's create two DataFrames with some overlapping columns − import pandas as pd # Creating dataframe1 dataFrame1 = pd.DataFrame({ "Car": ['BMW', 'Lexus', 'Tesla', 'Mustang', 'Mercedes', 'Jaguar'], "Cubic_Capacity": [2000, 1800, 1500, 2500, 2200, 3000], }) print("Dataframe1...", dataFrame1) # Creating dataframe2 dataFrame2 = pd.DataFrame({ ... Read More

Python Program to print all distinct uncommon digits present in two given numbers

AmitDiwan
Updated on 26-Mar-2026 13:16:16

296 Views

When it is required to print all the distinct uncommon digits that are present in two numbers, a method is defined that takes two integers as parameters. The method symmetric_difference() is used to get the uncommon digits that exist in one number but not in both. What are Uncommon Digits? Uncommon digits are digits that appear in one number but not in the other. For example, in numbers 567234 and 87953573214, the uncommon digits are 1, 6, 8, and 9. Example Below is a demonstration of finding distinct uncommon digits ? def distinct_uncommon_nums(val_1, val_2): ... Read More

Python Program to Split joined consecutive similar characters

AmitDiwan
Updated on 26-Mar-2026 13:15:58

370 Views

When working with strings containing consecutive similar characters, we often need to split them into groups. Python's groupby function from the itertools module provides an efficient way to group consecutive identical characters. Syntax The groupby() function groups consecutive equal elements from an iterable ? itertools.groupby(iterable, key=None) Example Let's split a string with consecutive similar characters into separate groups ? from itertools import groupby my_string = 'pppyyytthhhhhhhoooooonnn' print("The string is:") print(my_string) my_result = ["".join(grp) for elem, grp in groupby(my_string)] print("The result is:") print(my_result) The string is: ... Read More

Python - Fetch columns between two Pandas DataFrames by Intersection

AmitDiwan
Updated on 26-Mar-2026 13:15:40

2K+ Views

To fetch columns between two DataFrames by intersection, use the intersection() method. This method returns the common column names present in both DataFrames. Syntax dataframe.columns.intersection(other_dataframe.columns) Creating Sample DataFrames Let's create two DataFrames with some common and different columns ? import pandas as pd # Creating dataframe1 dataFrame1 = pd.DataFrame({ "Car": ['Bentley', 'Lexus', 'Tesla', 'Mustang', 'Mercedes', 'Jaguar'], "Cubic_Capacity": [2000, 1800, 1500, 2500, 2200, 3000], "Reg_Price": [7000, 1500, 5000, 8000, 9000, 6000] }) print("Dataframe1...") print(dataFrame1) Dataframe1... ... Read More

Advertisements