Fill Rainbow Color Under a Curve in Python Matplotlib

Rishikesh Kumar Rishi
Updated on 20-Sep-2021 09:54:32

727 Views

To fill rainbow color under a curve in Python Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a user-defined method, plot_rainbow_under_curve(), that could have a list of 7 rainbow colors and create a set of data points "x" using numpy.Iterate in the range of 0 to 7 and plot the curve and fill the area between that curve.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True def plot_rainbow_under_curve(): rainbow_colors = ['violet', 'indigo', ... Read More

Draw Axis Lines Inside a Plot in Matplotlib

Rishikesh Kumar Rishi
Updated on 20-Sep-2021 09:38:32

565 Views

To draw axis lines inside a plot in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Create x data points using numpy.Add an 'ax' to the figure as part of a subplot arrangement.Plot x and x**x data points using plot() method.Set the left and bottom positions at 0, whereas color of the right and top spines none.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = ... Read More

Set Same Scale for Subplots in Python Using Matplotlib

Rishikesh Kumar Rishi
Updated on 20-Sep-2021 09:32:07

3K+ Views

To set the same scale for subplot in Python using Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Add an 'ax1' to the figure as part of a subplot arrangement with nrows=2, ncols=1 and index=1.Add another axis 'ax2' to the figure as part of a subplot arrangement with nrows=2, ncols=1 and index=2, with shared X-axis (to set same scale for subplots)Create "t" data points to plot sine and cosine curves on axes ax1 and ax2.To display the figure, use show() method.Exampleimport ... Read More

Conditional Removal of Labels in Matplotlib Pie Chart

Rishikesh Kumar Rishi
Updated on 20-Sep-2021 09:29:16

2K+ Views

To remove labels from a Matplotlib pie chart based on a condition, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a Pandas dataframe of wwo-dimensional, size-mutable, potentially heterogeneous tabular data.Plot a pie chart, using pie() method with conditional removal of labels, such that if %age value is greater than 25, then only keep labels, otherwise remove them.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create a ... Read More

Fill NaN with Linear Interpolation in Python Pandas

AmitDiwan
Updated on 20-Sep-2021 09:25:51

672 Views

To fill NaN with Linear Interpolation, use the interpolate() method on the Pandas series. At first, import the required libraries −import pandas as pd import numpy as npCreate a Pandas series with some NaN values. We have set the NaN using the numpy np.nan −d = pd.Series([10, 20, np.nan, 40, 50, np.nan, 70, np.nan, 90, 100]) Find linear interpolation −d.interpolate()ExampleFollowing is the code −import pandas as pd import numpy as np # pandas series d = pd.Series([10, 20, np.nan, 40, 50, np.nan, 70, np.nan, 90, 100]) print"Series...", d # interpolate print"Linear Interpolation...", d.interpolate()OutputThis will produce the following ... Read More

Make a Frequency Histogram from Tuple Elements in Python

Rishikesh Kumar Rishi
Updated on 20-Sep-2021 09:23:49

3K+ Views

To make a frequency histogram from a list with tuple elements 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 tuples, data.Make lists of frequency and indices, after iterating the data.Make a bar plot usig bar() method.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data = [("a", 1), ("c", 3), ("d", 4), ("b", 2), ("e", 7), ("f", 3), ('g', 2)] ind = [] fre = [] for item in data: ... Read More

Group DataFrame Rows into List in Pandas

AmitDiwan
Updated on 20-Sep-2021 09:19:45

358 Views

To group dataframe rows into list, use the apply() function. At first, let us import the require library −import pandas as pdCreate DataFrame with 2 columns −dataFrame = pd.DataFrame(    {       "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] } )Grouping DataFrame into list with apply(list) −dataFrame = dataFrame.groupby('Car')['Units'].apply(list) ExampleFollowing is the code −import pandas as pd # Create DataFrame dataFrame = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'], "Units": ... Read More

Rotate Simple Matplotlib Axes

Rishikesh Kumar Rishi
Updated on 20-Sep-2021 09:18:12

12K+ Views

To rotate a simple matplotlib axes, we can take the following steps −Import the required packages −import matplotlib.pyplot as plt from matplotlib.transforms import Affine2D import mpl_toolkits.axisartist.floating_axes as floating_axesSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Make a tuple of axes extremes.Add a mutable 2D affine transformation, "t". Add a rotation (in degrees) to this transform in place.Add a transform from the source (curved) coordinate to target (rectilinear) coordinate.Add a floating axes "h" with the current figure with GridHelperCurveLinear() instance.Add an 'ax' to the figure as part of a ... Read More

Merge Pandas DataFrame with Right Outer Join in Python

AmitDiwan
Updated on 20-Sep-2021 09:10:56

519 Views

To merge Pandas DataFrame, use the merge() function. The right outer join is implemented on both the DataFrames by setting under the “how” parameter of the merge() function i.e. −how = “right”At first, let us import the pandas library with an alias −import pandas as pd Create two dataframes to be merged −# Create DataFrame1 dataFrame1 = pd.DataFrame(    {       "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90]    } ) # Create DataFrame2 dataFrame2 = pd.DataFrame(    {       "Car": ['BMW', 'Lexus', 'Tesla', 'Mustang', 'Mercedes', 'Jaguar'], "Reg_Price": ... Read More

Add 3D Subplot to a Matplotlib Figure

Rishikesh Kumar Rishi
Updated on 20-Sep-2021 09:09:37

3K+ Views

To add a 3D subplot to a matplotlib figure, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x, y and z data points using numpy.Create a new figure or activate an existing figure.Add an 'ax' to the figure as part of a subplot arrangement with projection='3d'.Plot x, y and z data points using plot() method.To display the figure, use .show() method.Examplefrom matplotlib import pyplot as plt import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create x, y and ... Read More

Advertisements