- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
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 a multivariate function in Python Matplotlib?
To plot a multivariate function in Python, we can take the following steps −
Steps
Set the figure size and adjust the padding between and around the subplots.
Create random x, y and z data points using numpy.
Create a figure and a set of subplots.
Create a scatter plot with x, y and z data points.
Create a colorbar for a ScalarMappable instance, s.
To display the figure, use show() method.
Example
import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True def func(x, y): return 3 * x + 4 * y - 2 + np.random.randn(30) x, y = np.random.randn(2, 30) y *= 100 z = func(x, y) fig, ax = plt.subplots() s = ax.scatter(x, y, c=z, s=100, marker='*', cmap='plasma') fig.colorbar(s) plt.show()
Output
It will produce the following output −
- Related Articles
- How to plot a function defined with def in Python? (Matplotlib)
- How to a plot stem plot in Matplotlib Python?
- How do I plot a step function with Matplotlib in Python?
- How to plot a density map in Python Matplotlib?
- How to plot signal in Matplotlib in Python?
- How to plot cdf in Matplotlib in Python?
- How to plot a layered image in Matplotlib in Python?
- How to plot a phase spectrum in Matplotlib in Python?
- How to plot MFCC in Python using Matplotlib?
- How to plot vectors in Python using Matplotlib?
- How to save a plot in Seaborn with Python (Matplotlib)?
- How to plot Exponentially Decaying Function using FuncAnimation in Matplotlib
- How to plot magnitude spectrum in Matplotlib in Python?
- How to show the Logarithmic plot of a cumulative distribution function in Matplotlib?
- How to plot a 3D density map in Python with Matplotlib?

Advertisements