Found 784 Articles for Data Visualization

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

Rishikesh Kumar Rishi
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?

Rishikesh Kumar Rishi
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?

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

966 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

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?

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

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

Rishikesh Kumar Rishi
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 avoid line color repetition in matplotlib.pyplot?

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

826 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 visualize values on logarithmic scale on matplotalib?

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

4K+ Views

To visualize values on logarithmic scale on matplotlib, we can use yscale('log').StepsImport matplotlib nd numpy.Set the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Use yscale('log') to visualize the values on a logarithmic scale.Plot x and y data points using plot method.Place a legend on the figure.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"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # x and y data points x = np.linspace(1, 100, 1000) y = np.log(x) ... Read More

How to change xticks font size in a matplotlib plot?

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

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

Advertisements