Matplotlib Articles - Page 7 of 98

Remove NaN values from a dataframe without fillna or Interpolate (Python Matplotlib)

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 11:47:54

2K+ Views

To remove NaN values from a dataframe without filter or interpolate, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create an array to make a Pandas data frame.One-dimensional ndarray with axis labels (including time series).Plotting interpolation, 'index', 'values' − Use the actual numerical values of the index.To display the figure, use show() method.Exampleimport numpy as np import pandas as pd from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Numpy array data = np.array([1., 1.2, 0.89, np.NAN,   ... Read More

How to specify different colors for different bars in a Python matplotlib histogram?

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 11:44:04

5K+ Views

To specify different colors for different bars in a matplotlib histogram, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Plot a histogram with random data with 100 sample data.Iterate in the range of number of bins and set random facecolor for each bar.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt import random import string # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Figure and set of subplots fig, ax = ... Read More

How do I fill a region with only hatch (no background colour) in matplotlib 2.0?

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 11:40:47

1K+ Views

To fill a region with only hatch (no background color) in matplotlib, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Initialize a variable n to store the number of sample data.Create a figure and a set of subplots.Plot the x and y data points.Fill the area between x and y with circle hatches, edgecolor="blue".To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Number of sample data n = 256 ... Read More

How to set a line color to orange, and specify line markers in Matplotlib?

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 11:37:53

3K+ Views

To set a line color to orange, and specify line markers in matplotlib, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot the x and y data points with the attributes color='orange' and marker='*'.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # x and y data points x = np.linspace(-5, 5, 100) y = np.sin(x) # Plot the data points with color ... Read More

How to deal with NaN values while plotting a boxplot using Python Matplotlib?

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 11:35:26

3K+ Views

To deal with NaN value while plotting a boxplot using Python, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Initialize a variable N for data samples and for range.Next create the random spread, center's data, flier high and low, get the concatenated data, and the filtered data.Create a box plot using boxplot() method.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Data samples N = 10 # Random spread ... Read More

How to plot a smooth line with matplotlib?

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 11:32:09

18K+ Views

To plot a smooth line with matplotlib, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create a list of data points, x and y.Plot the x and y data points.Create x_new and bspline data points for smooth line.Get y_new data points. Compute the (coefficients of) interpolating B-spline.Plot x_new and y_new data points using plot() method.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt from scipy import interpolate # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # x ... Read More

How to avoid line color repetition in matplotlib.pyplot?

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 11:23:09

1K+ Views

To avoid line color repetition in matplotlib.pyplot we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot the x and y data points using plot() method.In the plot() method, use a unique hexadecimal value for the color attribure, for example, color="#980ab5" to set the graph in a unique color. You can also specify a particular color of your choice, for example, color="green".To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] ... Read More

How to change xticks font size in a matplotlib plot?

Rishikesh Kumar Rishi
Updated on 08-Sep-2023 23:25:53

45K+ Views

To change the font size of xticks in a matplotlib plot, we can use the fontsize parameter.StepsImport matplotlib and numpy.Set the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot the x and y data points using plot() method.Set the font size of xticks using xticks() 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.50, 3.50] plt.rcParams["figure.autolayout"] = True # x and y data points x = np.linspace(-5, 5, 100) y = np.sin(x) ... Read More

How to plot multiple horizontal bars in one chart with matplotlib?

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 11:14:19

3K+ Views

To plot multiple horizontal bars in one chart with matplotlib, we can take the following steps −StepsImport the libraries pandas, matplotlib, and numpy.Set the figure size and adjust the padding between and around the subplots.Create an array for horizontal bar's position.Initialize a variable width for bar's width.Create a horizontal bar plot.Set Y-axis ticks and tick labels with some limit.Place a legend on the plot at the upper right location.To display the figure, use show() method.Exampleimport pandas import matplotlib.pyplot as plt import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Array ... Read More

How to shift the colorbar position to right in matplotlib?

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 11:11:11

3K+ Views

To shift the colorbar position to right in matplotlib, we can take the following steps −StepsImport numpy and matplotlib.Set the figure size and adjust the padding between and around the subplots.Initialize a variable N to store the number of sample data.Create x and y data points using numpy.Create a scatter plot using scatter() method with x and y data points.Add a colorbar to a plot, use the pad value for horizontal shift towards right or left.To display the figure, use show() method.Example# Import numpy and matplotlib import numpy as np from matplotlib import pyplot as plt # Set the ... Read More

Previous 1 ... 5 6 7 8 9 ... 98 Next
Advertisements