## Add a legend in a 3D scatterplot with scatter() in Matplotlib

Updated on 01-Feb-2022 11:52:09

4K+ Views

To add a legend in a 3D scatterplot with scatter() 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 x and y data points; make z1 and z2 data points list.Add a subplot to the current figure, with projection='3d'.Plot the x, y and z1 data points using plot() points on 2d axes, with marker *.Plot the x, y and z2 data points using plot() points on 2d axes, with marker o.Place legend on the figure.To display the figure ... Read More

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

Updated on 01-Feb-2022 11:47:54

1K+ 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?

Updated on 01-Feb-2022 11:44:04

4K+ 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?

Updated on 01-Feb-2022 11:40:47

827 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?

Updated on 01-Feb-2022 11:37:53

2K+ 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?

Updated on 01-Feb-2022 11:35:26

2K+ 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?

Updated on 01-Feb-2022 11:32:09

13K+ 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

## Representing voxels with matplotlib

Updated on 01-Feb-2022 11:29:01

2K+ Views

In 3D computer graphics, a voxel represents a value on a regular grid in three-dimensional space. We can say a voxel is a 3D equivalent of a pixel that is used in 2D. A pixel is a square inside of a 2D image with a position in a 2D grid and a single color value, whereas a voxel is a cube inside of a 3D model with a position inside a 3D grid and a single color value.To represent voxels with matplotlib, we can take the following steps −StepsSet the figure size and adjust the padding between and around the ... Read More

## How to get a Gantt plot using matplotlib?

Updated on 01-Feb-2022 11:25:48

479 Views

Gantt charts are widely used in project planning to show the project schedule. It's a type of bar chart that lists the tasks on the vertical axis and the time intervals on the horizontal axis. The width of the horizontal bars in the graph shows the duration of each activity.To plot a Gantt chart in matplotlib, we can use the broken_barh() method.StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Plot a horizontal sequence of rectangles.Set the y and x limits of the axes.To display the figure, use show() method.Exampleimport ... Read More

## How to avoid line color repetition in matplotlib.pyplot?

Updated on 01-Feb-2022 11:23:09

590 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

Previous 1 ... 6 7 8 9 10 ... 104 Next