MongoDB, the most popular NoSQL database, is an open-source document-oriented database. The term ‘NoSQL’ means ‘non-relational’. It means that MongoDB isn’t based on the table-like relational database structure but provides an altogether different mechanism for storage and retrieval of data. This format of storage is called BSON ( similar to JSON format).

Plotting sample data from MongoDB Atlas
Before Starting to plot the sample data make sure you have created an account on the MongoDB Cloud Atlas. If you have not created follow the below steps.
- Open the MongoDB Atlas Cloud from here.
- Create the account by choosing the package suitable for you (You may also choose the free version which will be enough for this article and for learning purpose).
- Click on the Cluster view positioned at the left menu bar.
- Click on the Ellipses button
(...)and select Load Sample Dataset. - After the sample dataset is added then click on the connect button.
- Then whitelist the IP address (choose your current IP address or type the 0.0.0.0/0 IP for allowing it to access from everywhere. Click the button shown in the below image.

- Then click connect to applications button.
- Copy the cluster_uri and paste it to a “course_cluster_uri”.
Approach:
- Import PyMongo and Axes3d and Matplotlib.
- Go to MongoDB Atlas Cloud by signing in.
- Paste the “course_cluster_uri” following the above steps.
- Get the client using “pymongo.MongoClient(course_url)” .
- Now set the query to filtering conditions and criteria by removing outliers that are clearly bad data.
- Convert cursor into a list.
- Now set the plot as “scatter/bar/hist” and also set Title, X-axis label, Y-axis label and legends.
- Don’t forget to type plt.show().
Below is the implementation.
# Using PyMongo to create plots import pymongo from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt course_cluster_uri = 'your_connection_string'course_client = pymongo.MongoClient(course_cluster_uri) # sample dataset db = course_client['sample_weatherdata'] # sample collection weather_data = db['data'] # remove outliers that are clearly bad data query = { 'pressure.value': { '$lt': 9999 }, 'airTemperature.value': { '$lt': 9999 }, 'wind.speed.rate': { '$lt': 500 }, } # convert our cursor into a list l = list(weather_data.find(query).limit(1000)) # pull out the 3 variables we care # about into their own respective lists pressures = [x['pressure']['value'] for x in l] air_temps = [x['airTemperature']['value'] for x in l] wind_speeds = [x['wind']['speed']['rate'] for x in l] # here you'll write the code to plot pressures, # air_temps, and wind_speeds in a 3D plot plt.clf() fig = plt.figure() ax = fig.add_subplot(111, projection = '3d') ax.scatter(pressures, air_temps, wind_speeds) ax.set_xlabel("Pressure") ax.set_ylabel("Air Temperature") ax.set_zlabel("Wind Speed") plt.show() |

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Make Python API to access Mongo Atlas Database
- Python | Plotting column charts in excel sheet with data tables using XlsxWriter module
- Python | Plotting charts in excel sheet with Data Tools using XlsxWriter module | Set - 1
- Python | Plotting charts in excel sheet with data tools using XlsxWriter module | Set – 2
- Plotting Data on Google Map using Python's pygmaps package
- Plotting Geospatial Data using GeoPandas
- How to fetch data from MongoDB using Python?
- Python - Random Sample Training and Test Data from dictionary
- MongoDB Python | Insert and Update Data
- MongoDB python | Delete Data and Drop Collection
- Python | Plotting Google Map using gmplot package
- Python | Plotting Google Map using folium package
- Python | Geographical plotting using plotly
- Python | Plotting charts in excel sheet using openpyxl module | Set - 1
- Python | Plotting charts in excel sheet using openpyxl module | Set – 2
- Python | Plotting charts in excel sheet using openpyxl module | Set 3
- 3D Wireframe plotting in Python using Matplotlib
- Python | Plotting Area charts in excel sheet using XlsxWriter module
- Python | Plotting bar charts in excel sheet using XlsxWriter module
- Python | Plotting Radar charts in excel sheet using XlsxWriter module
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

