{"id":86930,"date":"2023-02-22T09:00:01","date_gmt":"2023-02-22T03:30:01","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=86930"},"modified":"2023-02-22T09:00:01","modified_gmt":"2023-02-22T03:30:01","slug":"scatter-plot-in-python","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/scatter-plot-in-python\/","title":{"rendered":"Scatter Plot in Python"},"content":{"rendered":"<p>In this tutorial, we will learn about scatter plot in Python. Let&#8217;s start!!<\/p>\n<h3>What is scatter plot in python?<\/h3>\n<p><span style=\"font-weight: 400\">One kind of graph that has dots plotted in it is called a scatter plot in Python. The data values are represented as dots on the plot. Using the matplotlib library, we will depict a scatter plot. Two sets of data are needed to create a scatter plot; one set of arrays represents the data on the x-axis, while the second set of arrays represents the data on the y-axis.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">matplotlib.pyplot.scatter()<\/pre>\n<p><span style=\"font-weight: 400\">In most cases, scatter plots are used to examine the relationship between the variables. The connections between the dataset are represented by the dots in the graph. To create a scatter plot, we utilise the scatter() function from the matplotlib library. The scatter plot shows the relationship between the two variables and how it varies for one variable.<\/span><\/p>\n<p><span style=\"font-weight: 400\">A comprehensive tool for creating static, animated, and interactive visualisations is offered by the Matplotlib toolbox for Python. It can produce scatter plots, 3-D plots, histograms, bar charts, pie charts, and line plots, among other types of Python graphs. We will learn everything there is to know about scatter plots from the matplotlib library.<\/span><\/p>\n<p><span style=\"font-weight: 400\">The simple scatter plot, a close relative of the line plot, is another often-used plot style. Here, the points are each individually represented by a dot, circle, or another shape rather than by line segments.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">Python Scatter() Function<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Users can build scatter plots with the use of matplotlib&#8217;s scatter() function. The data are read and a scatter plot is produced once the scatter() function has been called.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">Syntax of scatter plot<\/span><\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">matplotlib.pyplot.scatter(x_axis_data, y_axis_data, s=None, c=None,marker=None, cmap=None, vmin=None, vmax=None, alpha=None, linewidths=None, edgecolors=None) \n<\/pre>\n<p><span style=\"font-weight: 400\">With the exception of x-axis data and y-axis data, every parameter in the syntax is optional. Their value will be set to none by default.<\/span><\/p>\n<p><span style=\"font-weight: 400\">The following parameters are passed to the scatter() method:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">An array of x-axis data is called x-axis data.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">y-axis data: An array of y-axis information<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">marker size s (can be scalar or array of size equal to the size of x or y)<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Color C of the Marker Color Sequence<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Marker-style writing<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">Let&#8217;s now construct a straightforward scatter using two arrays.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import matplotlib.pyplot as plt\n\nx =[1, 3, 1, 9, 5, 55, 0, 5, 7, 24, 56, 8, 2]\n\ny =[98, 87, 89, 86, 100, 88, 101, 89, 97, 72, 76, 87, 88]\n\nplt.scatter(x, y, c =\"blue\")\n\n# To show the plot\nplt.show()\n<\/pre>\n<p><b>Output:<\/b><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-87210\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/02\/python-scatter-function.webp\" alt=\"python scatter function\" width=\"415\" height=\"302\" \/><\/p>\n<p><span style=\"font-weight: 400\">Here, the x-axis denotes the x, while the y-axis denotes y. The scores of each student are represented by each and every dot in the plot.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">Randomly distributed data scatter plot<\/span><\/h3>\n<p><span style=\"font-weight: 400\">The dataset may include &#8220;n&#8221; different values in addition to randomly generated values. Let&#8217;s examine an example where 100 random values are distributed evenly among two arrays using a normal data distribution.<\/span><\/p>\n<p><span style=\"font-weight: 400\">The mean will be set to 10 with a standard deviation of 2 for the first array in the dataset, and to 20 with a standard deviation of 5 for the second array.<\/span><\/p>\n<p><strong>Example-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#importing library\nimport matplotlib.pyplot as plt\n#datasets\nstudents_id = [1,2,3,4,5,6,7,8,9,10]\nstudents_marks = [98,97,87,78,64,55,68,74,59,35]\n#scatter plot for the dataset\nplt.scatter(students_id, students_marks)\nplt.show()\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-87211\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/02\/randomly-distributed-data-scatter-plot.webp\" alt=\"randomly distributed data scatter plot\" width=\"415\" height=\"302\" \/><\/p>\n<h3><span style=\"font-weight: 400\">Compare datasets using Plots in Python<\/span><\/h3>\n<p><span style=\"font-weight: 400\">The graph of a scatter plot can potentially include more than one dataset. Let&#8217;s look at an example of code that compares two distinct datasets.<\/span><\/p>\n<p><strong>Example &#8211; <\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import matplotlib.pyplot as plt\nimport numpy as np\n#Maths Marks\nstudents_id = np.array([1,2,3,4,5,6,7,8,9,10])\nstudents_marks = np.array([98,97,87,78,64,55,68,74,59,35])\nplt.scatter(students_id, students_marks)\n\n#science marks\nstudents_id = np.array([1,2,3,4,5,6,7,8,9,10])\nstudents_marks = np.array([58,99,68,75,53,35,98,96,85,63,])\nplt.scatter(students_id, students_marks)\n\nplt.show()\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-87212\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/02\/compare-plots-in-python.webp\" alt=\"compare plots in python\" width=\"415\" height=\"302\" \/><\/p>\n<h3><span style=\"font-weight: 400\">ColorMap in Python<\/span><\/h3>\n<p><span style=\"font-weight: 400\">The matplotlib library&#8217;s collection of colours is listed in the colour map. Every single hue has a distinct value ranging from 0 to 100.<\/span><\/p>\n<h4><span style=\"font-weight: 400\">How to use colormap in the scatter plot?<\/span><\/h4>\n<p><span style=\"font-weight: 400\">Given the value of the colormaps in the code, we can define the colormap using the keyword &#8220;viridis&#8221; since it is one of the built-in colormaps in the matplotlib package. &#8220;cmap&#8221; is a keyword parameter to specify the colormap.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">Scatter plots in Dash<\/span><\/h3>\n<p>The best approach to create analytical Python programmes using Plotly figures is with Dash. Run pip instal dash, click &#8220;Download&#8221; to acquire the source code, then launch python app.py to launch the application below.<\/p>\n<h3><span style=\"font-weight: 400\">Scatter plots and Categorical Axes<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Any kind of cartesian axis, such as linear, logarithmic, categorical, or date axes, can be used to create scatter plots.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">Line plots on Date axes<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Any sort of cartesian axis, such as linear, logarithmic, category, or date axes, can be used to create a line plot. Time-series charts are typically used to describe line plots on date axes.<\/span><\/p>\n<p><span style=\"font-weight: 400\">When the associated data are either ISO-formatted date strings, a date pandas column, or a DateTime NumPy array, Plotly automatically sets the axis type to a date format.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">Alpha<\/span><\/h3>\n<p><span style=\"font-weight: 400\">The transparency of the graph&#8217;s dots can also be changed by the user. We utilise the &#8220;alpha&#8221; option to denote transparency. Alpha can be between 0 and 1. The range 0 represents complete transparency, while the range 1 represents total opacity.<\/span><\/p>\n<p><strong>Example-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import matplotlib.pyplot as plt\nimport numpy as np\nstudents_id = [1,2,3,4,5,6,7,8,9,10]\nstudents_marks = [99,96,84,73,68,55,64,78,52,35]\nsizes = np.array([10,20,30,40,50,60,70,80,90,100])\n\nplt.scatter(students_id, students_marks, color = 'black', s=sizes, alpha = 0.4)\n\nplt.show()\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-87218\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/02\/scatter-plots-and-categorical-axes.webp\" alt=\"scatter plots and categorical axes\" width=\"415\" height=\"302\" \/><\/p>\n<h3><span style=\"font-weight: 400\">Shapes in scatter plot<\/span><\/h3>\n<p><span style=\"font-weight: 400\">The graph&#8217;s representation shape can be altered by the user. It shows up as a dot by default, but you can change it to a square, triangle, star, etc.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">Conclusion<\/span><\/h3>\n<p>This is all about scatter plots in python. Hope<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will learn about scatter plot in Python. Let&#8217;s start!! What is scatter plot in python? One kind of graph that has dots plotted in it is called a scatter plot&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":87209,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1053],"tags":[4844],"class_list":["post-86930","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-scatter-plot-in-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Scatter Plot in Python - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn about Scatter Plot in Python. See its syntax, Python Scatter() Function, Randomly distributed data scatter plot etc,\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/scatter-plot-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Scatter Plot in Python - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn about Scatter Plot in Python. See its syntax, Python Scatter() Function, Randomly distributed data scatter plot etc,\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/scatter-plot-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-22T03:30:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/02\/python-scatter-plot.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Scatter Plot in Python - TechVidvan","description":"Learn about Scatter Plot in Python. See its syntax, Python Scatter() Function, Randomly distributed data scatter plot etc,","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/scatter-plot-in-python\/","og_locale":"en_US","og_type":"article","og_title":"Scatter Plot in Python - TechVidvan","og_description":"Learn about Scatter Plot in Python. See its syntax, Python Scatter() Function, Randomly distributed data scatter plot etc,","og_url":"https:\/\/techvidvan.com\/tutorials\/scatter-plot-in-python\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2023-02-22T03:30:01+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/02\/python-scatter-plot.webp","type":"image\/webp"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/scatter-plot-in-python\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/scatter-plot-in-python\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Scatter Plot in Python","datePublished":"2023-02-22T03:30:01+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/scatter-plot-in-python\/"},"wordCount":781,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/scatter-plot-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/02\/python-scatter-plot.webp","keywords":["Scatter Plot in Python"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/scatter-plot-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/scatter-plot-in-python\/","url":"https:\/\/techvidvan.com\/tutorials\/scatter-plot-in-python\/","name":"Scatter Plot in Python - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/scatter-plot-in-python\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/scatter-plot-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/02\/python-scatter-plot.webp","datePublished":"2023-02-22T03:30:01+00:00","description":"Learn about Scatter Plot in Python. See its syntax, Python Scatter() Function, Randomly distributed data scatter plot etc,","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/scatter-plot-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/scatter-plot-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/scatter-plot-in-python\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/02\/python-scatter-plot.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/02\/python-scatter-plot.webp","width":1200,"height":628,"caption":"python scatter plot"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/scatter-plot-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Scatter Plot in Python"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/86930","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=86930"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/86930\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/87209"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=86930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=86930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=86930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}