{"id":3008,"date":"2024-03-27T11:23:27","date_gmt":"2024-03-27T06:23:27","guid":{"rendered":"https:\/\/afzalbadshah.com\/?p=3008"},"modified":"2024-03-27T11:23:31","modified_gmt":"2024-03-27T06:23:31","slug":"visualizing-data-from-mongodb-collection-using-python","status":"publish","type":"post","link":"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/","title":{"rendered":"Visualizing Data from MongoDB Collection using Python"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Data visualization is a crucial aspect of data analysis, allowing us to gain insights and make informed decisions. MongoDB, a popular NoSQL database, offers flexibility in storing and retrieving data, making it a preferred choice for many applications. In this tutorial, we will explore how to visualize data retrieved from a MongoDB collection using Python. <a href=\"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/data-driven-applications-using-mongodb-python-and-google-colab\/\" target=\"_blank\" rel=\"noopener\" title=\"\">You can visit the detailed tutorial on MongoDB and Data Science here. <\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Code Overview<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Below is the Python code to connect to a MongoDB Atlas cluster, retrieve data from a specified collection, and visualize it using matplotlib;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Import Required Libraries\nimport pymongo\nimport matplotlib.pyplot as plt\n\n# Connect to MongoDB Atlas\nclient = pymongo.MongoClient(\"mongodb+srv:\/\/user:password@cluster0.ergtejf.mongodb.net\/?retryWrites=true&amp;w=majority&amp;appName=Cluster0\")\n\n# Select the Database and Collection\ndb = client.database\ncollection = db.collection\n\n# Define a Function to Plot Data\ndef plot_data():\n    try:\n        # Retrieve data from MongoDB Atlas\n        cursor = collection.find()\n\n        # Initialize lists to store ids\n        ages = &#91;]\n\n        # Extract ids from documents\n        for document in cursor:\n            ages.append(document&#91;'age'])\n\n        # Plotting\n        plt.figure(figsize=(10, 6))\n        plt.plot(ages)\n        plt.title('ID Data from MongoDB Collection')\n        plt.xlabel('Index')\n        plt.ylabel('ID')\n        plt.grid(True)\n        plt.show()\n\n    except Exception as e:\n        print(\"An error occurred:\", e)\n\n# Call the Function to Plot Data\nplot_data()<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Explanation of Code<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Import Required Libraries<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Import Required Libraries\nimport pymongo  # Importing pymongo library for MongoDB interaction\nimport matplotlib.pyplot as plt  # Importing matplotlib.pyplot for plotting<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This line imports necessary libraries for our program, including <code>pymongo<\/code> for MongoDB interaction and <code>matplotlib.pyplot<\/code> for plotting.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Connect to MongoDB Atlas<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Connect to MongoDB Atlas\nclient = pymongo.MongoClient(\"mongodb+srv:\/\/user:password@cluster0.ergtejf.mongodb.net\/?retryWrites=true&amp;w=majority&amp;appName=Cluster0\")  # Establishing connection to MongoDB Atlas<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This section establishes a connection to MongoDB Atlas by providing the connection string generated from the MongoDB dashboard. Use your database connection string with correct username and password.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Select the Database and Collection<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Select the Database and Collection\ndb = client.database# Selecting the \"afzal\" database\ncollection = db.collection  # Selecting the \"afzal\" collection within the database<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, we specify the database and collection within MongoDB that we want to retrieve data from. In this case, it&#8217;s the &#8220;database&#8221; database and &#8220;collection&#8221; collection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Define a Function to Plot Data<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Define a Function to Plot Data\ndef plot_data():\n    try:\n        # Retrieve data from MongoDB Atlas\n        cursor = collection.find()  # Retrieving data from the specified collection\n\n        # Initialize lists to store ids\n        ages = &#91;]  # Initializing an empty list to store ids from documents\n\n        # Extract ids from documents\n        for document in cursor:\n            ages.append(document&#91;'age'])  # Appending each 'id' to the ids list\n\n        # Plotting\n        plt.figure(figsize=(10, 6))  # Setting figure size\n        plt.plot(ages)  # Plotting the ids data\n        plt.title('ID Data from MongoDB Collection')  # Setting title for the plot\n        plt.xlabel('Index')  # Setting label for x-axis\n        plt.ylabel('ID')  # Setting label for y-axis\n        plt.grid(True)  # Enabling grid lines\n        plt.show()  # Displaying the plot\n\n    except Exception as e:\n        print(\"An error occurred:\", e)  # Handling exceptions if any error occurs during the process<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This section defines a function named <code>plot_data()<\/code> to encapsulate the process of retrieving data from MongoDB and plotting it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Retrieve Data from MongoDB Atlas:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Retrieve Data from MongoDB Atlas\ncursor = collection.find()  # Retrieving data from the specified collection<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We use the <code>find()<\/code> method to retrieve data from the specified MongoDB collection. The results are stored in a cursor.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Initialize Lists and Extract IDs:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Initialize Lists and Extract IDs\nids = &#91;]  # Initializing an empty list to store ids from documents\nfor document in cursor:\n    ids.append(document&#91;'id'])  # Appending each 'id' to the ids list<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We initialize an empty list named <code>ids<\/code> to store the &#8216;id&#8217; field from each document retrieved from MongoDB. Then, we iterate through the cursor and append each &#8216;id&#8217; to the <code>ids<\/code> list.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Plotting:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Plotting\nplt.figure(figsize=(10, 6))  # Setting figure size\nplt.plot(ids)  # Plotting the ids data\nplt.title('ID Data from MongoDB Collection')  # Setting title for the plot\nplt.xlabel('Index')  # Setting label for x-axis\nplt.ylabel('ID')  # Setting label for y-axis\nplt.grid(True)  # Enabling grid lines\nplt.show()  # Displaying the plot<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Using <code>matplotlib<\/code>, we plot the data stored in the <code>ids<\/code> list. We set labels for the axes, title for the plot, and enable grid lines for better visualization.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"640\" height=\"412\" src=\"https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/03\/Data-Visulization.png?resize=640%2C412&#038;ssl=1\" alt=\"\" class=\"wp-image-3012\" srcset=\"https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/03\/Data-Visulization.png?w=850&amp;ssl=1 850w, https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/03\/Data-Visulization.png?resize=300%2C193&amp;ssl=1 300w, https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/03\/Data-Visulization.png?resize=768%2C494&amp;ssl=1 768w, https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/03\/Data-Visulization.png?resize=420%2C270&amp;ssl=1 420w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Exception Handling:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>except Exception as e:\n    print(\"An error occurred:\", e)  # Handling exceptions if any error occurs during the process<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We include exception handling to catch any errors that might occur during the process of data retrieval or plotting.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Call the Function to Plot Data:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Call the Function to Plot Data\nplot_data()  # Calling the function to execute the code and visualize the data<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, we call the <code>plot_data()<\/code> function to execute the code and visualize the data from the MongoDB collection.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Data visualization is a crucial aspect of data analysis, allowing us to gain insights and make informed decisions. MongoDB, a popular NoSQL database, offers flexibility in storing and retrieving data, making it a preferred choice for many applications. In this tutorial, we will explore how to visualize data retrieved from a MongoDB collection using Python. You can visit the detailed tutorial on MongoDB and Data Science here. Code Overview Below is the Python code to connect to a MongoDB Atlas&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":3014,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[489],"tags":[549,522,502],"class_list":["post-3008","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-driven-applications-using-mongodb-python-and-google-colab","tag-data-visulization","tag-mongodb","tag-python"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Data visualization is a crucial aspect of data analysis, allowing us to gain insights and make informed decisions. MongoDB, a popular NoSQL database, offers flexibility in storing and retrieving data, making it a preferred choice for many applications. In this tutorial, we will explore how to visualize data retrieved from a MongoDB collection using Python.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Afzal Badshah, PhD\"\/>\n\t<meta name=\"google-site-verification\" content=\"B8FNGv4w1toMpU3HUnD_SN9H9YMtp1ObsLuEDuirArI\" \/>\n\t<meta name=\"p:domain_verify\" content=\"87b5ca26c36438b20581a102dc290a47\" \/>\n\t<meta name=\"yandex-verification\" content=\"0eb3e2a9157fd34d\" \/>\n\t<meta name=\"keywords\" content=\"data visulization,mongodb,python,data driven applicatons (mongodb, python, google colab)\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_GB\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Afzal Badshah, PhD - Unlocking Mastery in Parenting, Teaching, Learning, Academic, and Life Skills: Your Guide to Excellence\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Visualizing Data from MongoDB Collection using Python - Afzal Badshah, PhD\" \/>\n\t\t<meta property=\"og:description\" content=\"Data visualization is a crucial aspect of data analysis, allowing us to gain insights and make informed decisions. MongoDB, a popular NoSQL database, offers flexibility in storing and retrieving data, making it a preferred choice for many applications. In this tutorial, we will explore how to visualize data retrieved from a MongoDB collection using Python.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/afzalbadshah.com\/wp-content\/uploads\/2024\/03\/Slide1-9-jpg.webp\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/afzalbadshah.com\/wp-content\/uploads\/2024\/03\/Slide1-9-jpg.webp\" \/>\n\t\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2024-03-27T06:23:27+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2024-03-27T06:23:31+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/web.facebook.com\/abmanduri\/\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@DrAFZALBADSHAH\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Visualizing Data from MongoDB Collection using Python - Afzal Badshah, PhD\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Data visualization is a crucial aspect of data analysis, allowing us to gain insights and make informed decisions. MongoDB, a popular NoSQL database, offers flexibility in storing and retrieving data, making it a preferred choice for many applications. In this tutorial, we will explore how to visualize data retrieved from a MongoDB collection using Python.\" \/>\n\t\t<meta name=\"twitter:creator\" content=\"@DrAFZALBADSHAH\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/afzalbadshah.com\/wp-content\/uploads\/2024\/03\/Slide1-9-jpg.webp\" \/>\n\t\t<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t\t<meta name=\"twitter:data1\" content=\"Afzal Badshah, PhD\" \/>\n\t\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/03\\\/27\\\/visualizing-data-from-mongodb-collection-using-python\\\/#blogposting\",\"name\":\"Visualizing Data from MongoDB Collection using Python - Afzal Badshah, PhD\",\"headline\":\"Visualizing Data from MongoDB Collection using Python\",\"author\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/author\\\/afzalbadshah-com\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/#person\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/afzalbadshah.com\\\/wp-content\\\/uploads\\\/2024\\\/03\\\/Slide1-9-jpg.webp?fit=1280%2C720&ssl=1\",\"width\":1280,\"height\":720},\"datePublished\":\"2024-03-27T11:23:27+05:00\",\"dateModified\":\"2024-03-27T11:23:31+05:00\",\"inLanguage\":\"en-GB\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/03\\\/27\\\/visualizing-data-from-mongodb-collection-using-python\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/03\\\/27\\\/visualizing-data-from-mongodb-collection-using-python\\\/#webpage\"},\"articleSection\":\"Data Driven Applicatons (MongoDB, Python, Google Colab), Data visulization, Mongodb, python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/03\\\/27\\\/visualizing-data-from-mongodb-collection-using-python\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/afzalbadshah.com\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/#listItem\",\"name\":\"Courses\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/#listItem\",\"position\":2,\"name\":\"Courses\",\"item\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/data-driven-applications-using-mongodb-python-and-google-colab\\\/#listItem\",\"name\":\"Data Driven Applicatons (MongoDB, Python, Google Colab)\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/data-driven-applications-using-mongodb-python-and-google-colab\\\/#listItem\",\"position\":3,\"name\":\"Data Driven Applicatons (MongoDB, Python, Google Colab)\",\"item\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/data-driven-applications-using-mongodb-python-and-google-colab\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/03\\\/27\\\/visualizing-data-from-mongodb-collection-using-python\\\/#listItem\",\"name\":\"Visualizing Data from MongoDB Collection using Python\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/#listItem\",\"name\":\"Courses\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/03\\\/27\\\/visualizing-data-from-mongodb-collection-using-python\\\/#listItem\",\"position\":4,\"name\":\"Visualizing Data from MongoDB Collection using Python\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/category\\\/courses\\\/data-driven-applications-using-mongodb-python-and-google-colab\\\/#listItem\",\"name\":\"Data Driven Applicatons (MongoDB, Python, Google Colab)\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/#person\",\"name\":\"Afzal Badshah, PhD\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/03\\\/27\\\/visualizing-data-from-mongodb-collection-using-python\\\/#personImage\",\"url\":\"https:\\\/\\\/afzalbadshah.com\\\/wp-content\\\/litespeed\\\/avatar\\\/27d3d5e33aa81b3152e368c66871f22f.jpg?ver=1787150587\",\"width\":96,\"height\":96,\"caption\":\"Afzal Badshah, PhD\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/author\\\/afzalbadshah-com\\\/#author\",\"url\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/author\\\/afzalbadshah-com\\\/\",\"name\":\"Afzal Badshah, PhD\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/03\\\/27\\\/visualizing-data-from-mongodb-collection-using-python\\\/#authorImage\",\"url\":\"https:\\\/\\\/afzalbadshah.com\\\/wp-content\\\/litespeed\\\/avatar\\\/27d3d5e33aa81b3152e368c66871f22f.jpg?ver=1787150587\",\"width\":96,\"height\":96,\"caption\":\"Afzal Badshah, PhD\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/03\\\/27\\\/visualizing-data-from-mongodb-collection-using-python\\\/#webpage\",\"url\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/03\\\/27\\\/visualizing-data-from-mongodb-collection-using-python\\\/\",\"name\":\"Visualizing Data from MongoDB Collection using Python - Afzal Badshah, PhD\",\"description\":\"Data visualization is a crucial aspect of data analysis, allowing us to gain insights and make informed decisions. MongoDB, a popular NoSQL database, offers flexibility in storing and retrieving data, making it a preferred choice for many applications. In this tutorial, we will explore how to visualize data retrieved from a MongoDB collection using Python.\",\"inLanguage\":\"en-GB\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/03\\\/27\\\/visualizing-data-from-mongodb-collection-using-python\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/author\\\/afzalbadshah-com\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/author\\\/afzalbadshah-com\\\/#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/afzalbadshah.com\\\/wp-content\\\/uploads\\\/2024\\\/03\\\/Slide1-9-jpg.webp?fit=1280%2C720&ssl=1\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/03\\\/27\\\/visualizing-data-from-mongodb-collection-using-python\\\/#mainImage\",\"width\":1280,\"height\":720},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/index.php\\\/2024\\\/03\\\/27\\\/visualizing-data-from-mongodb-collection-using-python\\\/#mainImage\"},\"datePublished\":\"2024-03-27T11:23:27+05:00\",\"dateModified\":\"2024-03-27T11:23:31+05:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/#website\",\"url\":\"https:\\\/\\\/afzalbadshah.com\\\/\",\"name\":\"Afzal Badshah, PhD\",\"alternateName\":\"Afzal Badshah\",\"description\":\"Unlocking Mastery in Parenting, Teaching, Learning, Academic, and Life Skills: Your Guide to Excellence\",\"inLanguage\":\"en-GB\",\"publisher\":{\"@id\":\"https:\\\/\\\/afzalbadshah.com\\\/#person\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Visualizing Data from MongoDB Collection using Python - Afzal Badshah, PhD","description":"Data visualization is a crucial aspect of data analysis, allowing us to gain insights and make informed decisions. MongoDB, a popular NoSQL database, offers flexibility in storing and retrieving data, making it a preferred choice for many applications. In this tutorial, we will explore how to visualize data retrieved from a MongoDB collection using Python.","canonical_url":"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/","robots":"max-image-preview:large","keywords":"data visulization,mongodb,python,data driven applicatons (mongodb, python, google colab)","webmasterTools":{"google-site-verification":"B8FNGv4w1toMpU3HUnD_SN9H9YMtp1ObsLuEDuirArI","p:domain_verify":"87b5ca26c36438b20581a102dc290a47","yandex-verification":"0eb3e2a9157fd34d","miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/#blogposting","name":"Visualizing Data from MongoDB Collection using Python - Afzal Badshah, PhD","headline":"Visualizing Data from MongoDB Collection using Python","author":{"@id":"https:\/\/afzalbadshah.com\/index.php\/author\/afzalbadshah-com\/#author"},"publisher":{"@id":"https:\/\/afzalbadshah.com\/#person"},"image":{"@type":"ImageObject","url":"https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/03\/Slide1-9-jpg.webp?fit=1280%2C720&ssl=1","width":1280,"height":720},"datePublished":"2024-03-27T11:23:27+05:00","dateModified":"2024-03-27T11:23:31+05:00","inLanguage":"en-GB","mainEntityOfPage":{"@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/#webpage"},"isPartOf":{"@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/#webpage"},"articleSection":"Data Driven Applicatons (MongoDB, Python, Google Colab), Data visulization, Mongodb, python"},{"@type":"BreadcrumbList","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com#listItem","position":1,"name":"Home","item":"https:\/\/afzalbadshah.com","nextItem":{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/#listItem","name":"Courses"}},{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/#listItem","position":2,"name":"Courses","item":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/","nextItem":{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/data-driven-applications-using-mongodb-python-and-google-colab\/#listItem","name":"Data Driven Applicatons (MongoDB, Python, Google Colab)"},"previousItem":{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/data-driven-applications-using-mongodb-python-and-google-colab\/#listItem","position":3,"name":"Data Driven Applicatons (MongoDB, Python, Google Colab)","item":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/data-driven-applications-using-mongodb-python-and-google-colab\/","nextItem":{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/#listItem","name":"Visualizing Data from MongoDB Collection using Python"},"previousItem":{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/#listItem","name":"Courses"}},{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/#listItem","position":4,"name":"Visualizing Data from MongoDB Collection using Python","previousItem":{"@type":"ListItem","@id":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/data-driven-applications-using-mongodb-python-and-google-colab\/#listItem","name":"Data Driven Applicatons (MongoDB, Python, Google Colab)"}}]},{"@type":"Person","@id":"https:\/\/afzalbadshah.com\/#person","name":"Afzal Badshah, PhD","image":{"@type":"ImageObject","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/#personImage","url":"https:\/\/afzalbadshah.com\/wp-content\/litespeed\/avatar\/27d3d5e33aa81b3152e368c66871f22f.jpg?ver=1787150587","width":96,"height":96,"caption":"Afzal Badshah, PhD"}},{"@type":"Person","@id":"https:\/\/afzalbadshah.com\/index.php\/author\/afzalbadshah-com\/#author","url":"https:\/\/afzalbadshah.com\/index.php\/author\/afzalbadshah-com\/","name":"Afzal Badshah, PhD","image":{"@type":"ImageObject","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/#authorImage","url":"https:\/\/afzalbadshah.com\/wp-content\/litespeed\/avatar\/27d3d5e33aa81b3152e368c66871f22f.jpg?ver=1787150587","width":96,"height":96,"caption":"Afzal Badshah, PhD"}},{"@type":"WebPage","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/#webpage","url":"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/","name":"Visualizing Data from MongoDB Collection using Python - Afzal Badshah, PhD","description":"Data visualization is a crucial aspect of data analysis, allowing us to gain insights and make informed decisions. MongoDB, a popular NoSQL database, offers flexibility in storing and retrieving data, making it a preferred choice for many applications. In this tutorial, we will explore how to visualize data retrieved from a MongoDB collection using Python.","inLanguage":"en-GB","isPartOf":{"@id":"https:\/\/afzalbadshah.com\/#website"},"breadcrumb":{"@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/#breadcrumblist"},"author":{"@id":"https:\/\/afzalbadshah.com\/index.php\/author\/afzalbadshah-com\/#author"},"creator":{"@id":"https:\/\/afzalbadshah.com\/index.php\/author\/afzalbadshah-com\/#author"},"image":{"@type":"ImageObject","url":"https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/03\/Slide1-9-jpg.webp?fit=1280%2C720&ssl=1","@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/#mainImage","width":1280,"height":720},"primaryImageOfPage":{"@id":"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/#mainImage"},"datePublished":"2024-03-27T11:23:27+05:00","dateModified":"2024-03-27T11:23:31+05:00"},{"@type":"WebSite","@id":"https:\/\/afzalbadshah.com\/#website","url":"https:\/\/afzalbadshah.com\/","name":"Afzal Badshah, PhD","alternateName":"Afzal Badshah","description":"Unlocking Mastery in Parenting, Teaching, Learning, Academic, and Life Skills: Your Guide to Excellence","inLanguage":"en-GB","publisher":{"@id":"https:\/\/afzalbadshah.com\/#person"}}]},"og:locale":"en_GB","og:site_name":"Afzal Badshah, PhD - Unlocking Mastery in Parenting, Teaching, Learning, Academic, and Life Skills: Your Guide to Excellence","og:type":"article","og:title":"Visualizing Data from MongoDB Collection using Python - Afzal Badshah, PhD","og:description":"Data visualization is a crucial aspect of data analysis, allowing us to gain insights and make informed decisions. MongoDB, a popular NoSQL database, offers flexibility in storing and retrieving data, making it a preferred choice for many applications. In this tutorial, we will explore how to visualize data retrieved from a MongoDB collection using Python.","og:url":"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/","og:image":"https:\/\/afzalbadshah.com\/wp-content\/uploads\/2024\/03\/Slide1-9-jpg.webp","og:image:secure_url":"https:\/\/afzalbadshah.com\/wp-content\/uploads\/2024\/03\/Slide1-9-jpg.webp","og:image:width":1280,"og:image:height":720,"article:published_time":"2024-03-27T06:23:27+00:00","article:modified_time":"2024-03-27T06:23:31+00:00","article:publisher":"https:\/\/web.facebook.com\/abmanduri\/","twitter:card":"summary_large_image","twitter:site":"@DrAFZALBADSHAH","twitter:title":"Visualizing Data from MongoDB Collection using Python - Afzal Badshah, PhD","twitter:description":"Data visualization is a crucial aspect of data analysis, allowing us to gain insights and make informed decisions. MongoDB, a popular NoSQL database, offers flexibility in storing and retrieving data, making it a preferred choice for many applications. In this tutorial, we will explore how to visualize data retrieved from a MongoDB collection using Python.","twitter:creator":"@DrAFZALBADSHAH","twitter:image":"https:\/\/afzalbadshah.com\/wp-content\/uploads\/2024\/03\/Slide1-9-jpg.webp","twitter:label1":"Written by","twitter:data1":"Afzal Badshah, PhD","twitter:label2":"Est. reading time","twitter:data2":"4 minutes"},"aioseo_meta_data":{"post_id":"3008","title":null,"description":null,"keywords":[],"keyphrases":{"focus":{"keyphrase":"MongoDB","score":69,"analysis":{"keyphraseInTitle":{"score":9,"maxScore":9,"error":0},"keyphraseInDescription":{"score":9,"maxScore":9,"error":0},"keyphraseLength":{"score":9,"maxScore":9,"error":0,"length":1},"keyphraseInURL":{"score":5,"maxScore":5,"error":0},"keyphraseInIntroduction":{"score":9,"maxScore":9,"error":0},"keyphraseInSubHeadings":{"score":3,"maxScore":9,"error":1},"keyphraseInImageAlt":{"score":3,"maxScore":9,"error":1},"keywordDensity":{"type":"high","score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":true,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"BlogPosting","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2024-03-27 04:53:00","updated":"2025-06-10 22:07:26","focus_keyword":"MongoDB","additional_keywords":null,"truseo_locale":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/afzalbadshah.com\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/\" title=\"Courses\">Courses<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/data-driven-applications-using-mongodb-python-and-google-colab\/\" title=\"Data Driven Applicatons (MongoDB, Python, Google Colab)\">Data Driven Applicatons (MongoDB, Python, Google Colab)<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tVisualizing Data from MongoDB Collection using Python\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/afzalbadshah.com"},{"label":"Courses","link":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/"},{"label":"Data Driven Applicatons (MongoDB, Python, Google Colab)","link":"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/data-driven-applications-using-mongodb-python-and-google-colab\/"},{"label":"Visualizing Data from MongoDB Collection using Python","link":"https:\/\/afzalbadshah.com\/index.php\/2024\/03\/27\/visualizing-data-from-mongodb-collection-using-python\/"}],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/03\/Slide1-9-jpg.webp?fit=1280%2C720&ssl=1","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pf3emP-Mw","jetpack-related-posts":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/posts\/3008","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/comments?post=3008"}],"version-history":[{"count":5,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/posts\/3008\/revisions"}],"predecessor-version":[{"id":3015,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/posts\/3008\/revisions\/3015"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/media\/3014"}],"wp:attachment":[{"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/media?parent=3008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/categories?post=3008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/tags?post=3008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}