- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to plot and work with NaN values in Matplotlib?
To plot and work with NaN values in matplotlib, we can take the following steps −
Create data using numpy with some NaN values.
Use imshow() method to display data as an image, i.e., on a 2D regular raster, with a colormap and data (from step 1).
To display the figure, use show() method.
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data = np.array([[1., 1.2, 0.89, np.NAN], [1.2, np.NAN, 1.89, 2.09], [.78, .67, np.NAN, 1.78], [np.NAN, 1.56, 1.89, 2.78]] ) plt.imshow(data, cmap="gist_rainbow_r") plt.show()
- Related Articles
- How to plot masked and NaN values in Matplotlib?
- How can I plot NaN values as a special color with imshow in Matplotlib?
- How to deal with NaN values while plotting a boxplot using Python Matplotlib?
- Writing numerical values on the plot with Matplotlib
- Python - How to fill NAN values with mean in Pandas?
- How to plot with different scales in Matplotlib?
- How to plot with xgboost.XGBCClassifier.feature_importances_ model? (Matplotlib)
- Matplotlib – How to set xticks and yticks with imshow plot?
- How to create a Swarm Plot with Matplotlib?
- How to plot 2D math vectors with Matplotlib?
- How to plot a smooth line with matplotlib?
- How to plot a Pandas Dataframe with Matplotlib?
- How to plot 4D scatter-plot with custom colours and cutom area size in Python Matplotlib?
- Gaussian filtering an image with NaN in Python Matplotlib
- How to save a plot in Seaborn with Python (Matplotlib)?