Remove Whitespaces at the Bottom of a Matplotlib Graph

Rishikesh Kumar Rishi
Updated on 23-Sep-2021 08:43:20

4K+ Views

To remove whitespaces at the bottom of a Matplotlib graph, we can use tight layout or autoscale_on=False.stepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Add an 'ax' to the figure as part of a subplot arrangement.Plot a list of data points using plot() 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 fig = plt.figure() ax = fig.add_subplot(111, autoscale_on=False, xlim=(1, 5), ylim=(0, 10)) ax.plot([2, 5, 1, 2, 0, 7]) plt.show()OutputRead More

Understand Seaborn's Heatmap Annotation Format

Rishikesh Kumar Rishi
Updated on 23-Sep-2021 08:34:41

2K+ Views

To understand Seaborn's heatmap annotation format, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a Pandas dataframe with five columns.Plot the rectangular data as a color-encoded matrix, fmt=".2%" represents the annotation format.To display the figure, use show() method.ExampleExampleimport seaborn as sns import pandas as pd import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(np.random.random((5, 5)), columns=["a", "b", "c", "d", "e"]) sns.heatmap(df, annot=True, annot_kws={"size": 7}, fmt=".2%") plt.show()OutputRead More

Create a 100% Stacked Area Chart with Matplotlib

Rishikesh Kumar Rishi
Updated on 23-Sep-2021 08:03:50

1K+ Views

To create a 100% stacked Area Chart with Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a list of years.Make a dictionary, with list of population in respective years.Create a figure and a set of subplots.Draw a stacked Area Plot.Place a legend on the figure, at the location ''upper left''.Set the title, xlabel and ylabel.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True year = [1950, 1960, 1970, 1980, 1990, 2000, 2010, 2018] population_by_continent = {   ... Read More

Stack Multi-Level Column in a Pandas DataFrame

AmitDiwan
Updated on 22-Sep-2021 12:43:49

2K+ Views

To stack a multi-level column, use the stack() method. At first, import the required library −import pandas as pdCreate a multi-level column −items = pd.MultiIndex.from_tuples([('Maths', 'Mental Maths'), ('Maths', 'Discrete Mathematics'), ('Maths', 'Applied Mathematics')]) Now, create a DataFrame and set multi-level columns we set above −dataFrame = pd.DataFrame([[67, 86, 78], [56, 92, 97], [92, 95, 91]], index=['John', 'Tom', 'Henry'], columns=items)Stack the multi-level column −dataframe.stack()ExampleFollowing is the complete code −import pandas as pd # multi-level columns items = pd.MultiIndex.from_tuples([('Maths', 'Mental Maths'), ('Maths', 'Discrete Mathematics'), ('Maths', 'Applied Mathematics')]) # creating a DataFrame dataFrame = pd.DataFrame([[67, 86, 78], [56, 92, 97], ... Read More

Create Subset and Display Last Entry from Duplicate Values in Python Pandas

AmitDiwan
Updated on 22-Sep-2021 12:26:25

1K+ Views

To create a subset and display only the last entry from duplicate values, use the “keep” parameter with the ‘last” value in drop_duplicates() method. The drop_duplicates() method removed duplicates.Let us first create a DataFrame with 3 columns −dataFrame = pd.DataFrame({'Car': ['BMW', 'Mercedes', 'Lamborghini', 'BMW', 'Mercedes', 'Porsche'], 'Place': ['Delhi', 'Hyderabad', 'Chandigarh', 'Delhi', 'Hyderabad', 'Mumbai'], 'UnitsSold': [85, 70, 80, 95, 55, 90]})Removing duplicates and displaying last entry. Using keep parameter, we have set "last". Duplicate rows except the last entry will get deleted. We have considered a subset using the “subset” parameter −dataFrame2 = dataFrame.drop_duplicates(subset = ['Car', 'Place'], keep ='last').reset_index(drop = True)ExampleFollowing ... Read More

Get Shared Columns Between Two Pandas DataFrames using NumPy

AmitDiwan
Updated on 22-Sep-2021 12:19:15

291 Views

To get the columns shared by two DataFrames, use the intersect1d() method. This method is provided by numpy, so you need to import Numpy also with Pandas. Let us first import the required libraries −import pandas as pd import numpy as npCreate two DataFrames −# 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], "Units_Sold": [ 100, 110, 150, 80, 200, 90] }) # creating dataframe2 dataFrame2 = pd.DataFrame({"Car": ['BMW', 'Lexus', 'Tesla', 'Mustang', 'Mercedes', 'Jaguar'], "Units_Sold": [ 100, 110, 150, 80, 200, 90] ... Read More

Merge Pandas DataFrame with a Common Column

AmitDiwan
Updated on 22-Sep-2021 12:12:13

11K+ Views

To merge two Pandas DataFrame with common column, use the merge() function and set the ON parameter as the column name.At first, let us import the pandas library with an alias −import pandas as pdLet us create the 1st DataFrame −dataFrame1 = pd.DataFrame(    {       "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] } )Next, create the 2nd DataFrame −dataFrame2 = pd.DataFrame(    {       "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Mercedes', 'Jaguar'], "Reg_Price": [7000, 1500, 5000, 8000, 9000, 6000] } )Now, merge ... Read More

REST API Testing Tutorial: Sample Manual Test Case

Vineet Nanda
Updated on 22-Sep-2021 12:04:34

15K+ Views

APIApplication Programming Interface is a computing interface that communicates and helps exchange information between two separate systems. A system that executes an API involves functions that another system can also perform. It defines requests to be made, how to make the requests, formats that can be used, etc. between two different systems.API TestingIt is a software testing that evaluates APIs. Its purpose is to determine the functionality, dependability, performance, and security of the interfaces. Rather than standard user inputs such as keyboards and outputs, we use software to send calls, obtain output, and record the response of the system. These ... Read More

Merge Two Pandas DataFrames in Python

AmitDiwan
Updated on 22-Sep-2021 12:02:26

830 Views

To merge two Pandas DataFrame, use the merge() function. Just set both the DataFrames as a parameter of the merge() function.At first, let us import the required library with alias “pd” −import pandas as pdCreate the 1st DataFrame −# Create DataFrame1 dataFrame1 = pd.DataFrame(    {       "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90]    } )Next, create the 2nd DataFrame −# Create DataFrame2 dataFrame2 = pd.DataFrame(    {       "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Mercedes', 'Jaguar'], "Reg_Price": [7000, 1500, 5000, 8000, 9000, 6000] } ... Read More

Reliability Testing: Methods, Tools, and Examples

Vineet Nanda
Updated on 22-Sep-2021 12:01:31

1K+ Views

The chance of failure-free software execution for a set period of time in a given environment is defined as reliability.People nowadays naively believe in any program in this mechanized environment. People believe that whatever outcome the software system produces is always correct, therefore they follow it. That is a common mistake that we all make.Users believe that the data displayed is correct and that the software will always work properly. This is where the requirement for reliability testing arises.Reliability TestingReliability testing is a software testing procedure that determines if a piece of software can operate without fail for a set ... Read More

Advertisements