- 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 make a 4D plot with Matplotlib using arbitrary data?
To make a 4D plot, we can create x, y, z and c standard data points. Create a new figure or activate an existing figure.
Steps
Use figure() method to create a figure or activate an existing figure.
Add a figure as part of a subplot arrangement.
Create x, y, z and c data points using numpy.
Create a scatter plot using scatter method.
To display the figure, use show() method.
Example
from matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111, projection='3d') x = np.random.standard_normal(100) y = np.random.standard_normal(100) z = np.random.standard_normal(100) c = np.random.standard_normal(100) img = ax.scatter(x, y, z, c=c, cmap='YlOrRd', alpha=1) plt.show()
Output
Advertisements