{"id":31306,"date":"2023-05-13T12:25:52","date_gmt":"2023-05-13T12:25:52","guid":{"rendered":"https:\/\/holypython.com\/?page_id=31306"},"modified":"2023-05-13T18:11:17","modified_gmt":"2023-05-13T18:11:17","slug":"how-to-create-scatter-charts-with-bokeh","status":"publish","type":"page","link":"https:\/\/holypython.com\/python-visualization-tutorial\/how-to-create-scatter-charts-with-bokeh\/","title":{"rendered":"How to Create Scatter Charts with Bokeh"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-page\" data-elementor-id=\"31306\" class=\"elementor elementor-31306\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-38819ef elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"38819ef\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-top-column elementor-element elementor-element-98d652e\" data-id=\"98d652e\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-89b40fa elementor-widget elementor-widget-text-editor\" data-id=\"89b40fa\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>&lt;&lt;&lt; <a href=\"https:\/\/holypython.com\/python-visualization-tutorial\/\">Visualization Tutorials<\/a><br \/>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p><ol><li><a style=\"background-color: #ffffff;\" href=\"https:\/\/holypython.com\/how-to-create-plotly-animations-the-ultimate-guide\/\">How to <span style=\"font-weight: bold;\">create Plotly<\/span> animations<\/a><\/li><li><a href=\"https:\/\/holypython.com\/how-to-save-plotly-animations-the-ultimate-guide\/\">How to <span style=\"font-weight: bold;\">save Plotly<\/span> animations<\/a><\/li><li><a href=\"https:\/\/holypython.com\/how-to-create-map-charts-in-python-w-plotly-mapbox\/\">How to <span style=\"font-weight: bold;\">create Mapcharts<\/span> &#8211; Plotly &amp; Mapbox<\/a><\/li><li><a href=\"https:\/\/holypython.com\/how-to-create-matplotlib-animations-the-ultimate-guide\/\">How to <span style=\"font-weight: bold;\">create Matplotlib<\/span> animations<\/a><\/li><li><a href=\"https:\/\/holypython.com\/how-to-save-matplotlib-animations-the-ultimate-guide\/\">How to <span style=\"font-weight: bold;\">save Matplotlib<\/span> animations<\/a><\/li><li><a style=\"outline-width: 0px !important; user-select: auto !important;\" href=\"https:\/\/holypython.com\/python-visualization-tutorial\/python-chart-elements-title-axes-ticks-legend\/\"><span style=\"font-weight: bold;\">Titles, Axes, Ticks<\/span> &amp; Legend<\/a><\/li><li><a href=\"https:\/\/holypython.com\/a-guide-to-matplotlibs-built-in-styles\/\">Matplotlib Built-in <span style=\"font-weight: bold;\">Styles<\/span><\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-visualization-tutorial\/guide-to-python-animations-animating-line-charts\/\"><span style=\"font-weight: bold;\">Animated Line<\/span> Charts<\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-visualization-tutorial\/guide-to-python-animations-animating-multiple-lines\/\"><span style=\"font-weight: bold;\">Multi-line<\/span> Animation<\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-visualization-tutorial\/creating-stacked-area-charts-with-python\/\"><span style=\"font-weight: bold;\">Stacked Area<\/span> Charts<\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-visualization-tutorial\/word-cloud-visualization\/\"><span style=\"font-weight: bold;\">Word Cloud<\/span> Visualization<\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-visualization-tutorial\/creating-bar-chart-animations\/\"><span style=\"font-weight: bold;\">Bar Chart<\/span> Animations<\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-visualization-tutorial\/colors-with-python\/\"><span style=\"font-weight: bold;\">Colors<\/span> with Python<\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-visualization-tutorial\/creating-multiple-charts\/\">Creating <span style=\"font-weight: bold;\">Multiple Charts<\/span><\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-visualization-tutorial\/creating-hexbin-charts\/\">Creating\u00a0<span style=\"font-weight: bold;\">Hexbin Charts<\/span><\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-visualization-tutorial\/pcolor-and-pcolormesh\/\">Creating\u00a0<span style=\"font-weight: bold;\">Pcolor Charts<\/span><\/a><\/li><li><a href=\"https:\/\/holypython.com\/python-visualization-tutorial\/how-to-create-scatter-charts-with-bokeh\/\">Creating <span style=\"font-weight: bold;\">Bokeh Scatter Plot<\/span><\/a><\/li><\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-top-column elementor-element elementor-element-820bd33\" data-id=\"820bd33\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-2eacc4c elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"2eacc4c\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-1d7add4\" data-id=\"1d7add4\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-c9dba6c elementor-widget elementor-widget-heading\" data-id=\"c9dba6c\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h1 class=\"elementor-heading-title elementor-size-default\">How to Create Scatter Charts with Bokeh<\/h1>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-3a3ccc8\" data-id=\"3a3ccc8\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-57329d4 elementor-widget elementor-widget-raven-image\" data-id=\"57329d4\" data-element_type=\"widget\" data-widget_type=\"raven-image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"raven-image\">\r\n\t\t\t\t\t<figure class=\"wp-caption\">\r\n\t\t\r\n\t\t\r\n\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"1486\" height=\"1648\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/holypython_bokeh_scatter.png\" class=\"attachment-full size-full wp-image-31335\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/holypython_bokeh_scatter.png 1486w, https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/holypython_bokeh_scatter-271x300.png 271w, https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/holypython_bokeh_scatter-923x1024.png 923w, https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/holypython_bokeh_scatter-768x852.png 768w, https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/holypython_bokeh_scatter-1385x1536.png 1385w\" sizes=\"(max-width: 1486px) 100vw, 1486px\" \/>\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Word Cloud Tutorial<\/figcaption>\r\n\t\t\t\t\t\t<\/figure>\r\n\t\t\t\t\t<\/div>\r\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<div class=\"elementor-element elementor-element-98a498b elementor-widget elementor-widget-text-editor\" data-id=\"98a498b\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Contents<\/p><ul><li><a href=\"#intro\">Introduction<\/a><ol><li><a href=\"#bokeh\">Wordcloud library<\/a><\/li><li><span style=\"outline-width: 0px !important; user-select: auto !important;\"><a href=\"#example1\">Example 1: Bokeh Scatter Plot with Python<\/a><\/span><\/li><li><a href=\"#example2\">Example 2: Adding Labels to Bokeh Charts <\/a><\/li><\/ol><\/li><li><a style=\"background-color: #ffffff;\" href=\"#summary\">Summary<\/a><\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-eeece35 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"eeece35\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-883b749\" data-id=\"883b749\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-b3f3750 elementor-widget elementor-widget-menu-anchor\" data-id=\"b3f3750\" data-element_type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"intro\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-49a0273 elementor-widget elementor-widget-heading\" data-id=\"49a0273\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Introduction<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ad7412f elementor-widget elementor-widget-text-editor\" data-id=\"ad7412f\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Scatter plots are fundamental chart types that can be applied to many situations across industries. In this mini Python tutorial we will create a scatter chart using Python&#8217;s Bokeh visualization library.<\/p><p>Before we start this Python tutorial, if you are curious WHY someone would choose Bokeh as a Python visualization library here is an article I recently published: <a href=\"https:\/\/holypython.com\/benefits-of-bokeh-over-python-visualization-libraries-like-seaborn-matplotlib-plotly\/\">Benefits of Bokeh over Seaborn, Plotly &amp; Matplotlib<\/a>.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-084b6fd elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"084b6fd\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-934a245\" data-id=\"934a245\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-9041c45 elementor-widget elementor-widget-menu-anchor\" data-id=\"9041c45\" data-element_type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"bokeh\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f02020d elementor-widget elementor-widget-heading\" data-id=\"f02020d\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">1- Importing Bokeh Libraries<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3c265ee elementor-widget elementor-widget-text-editor\" data-id=\"3c265ee\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>If you&#8217;ve created charts using matplotlib, seaborn, plotly and others, you might realize that bokeh modules work in a slightly different way. We will import many functions from different modules which can be a bit confusing at first but they work really well and harmoniously.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ecd4e90 elementor-widget elementor-widget-html\" data-id=\"ecd4e90\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from bokeh.io import output_file, show\nfrom bokeh.models import ColumnDataSource, LabelSet\nfrom bokeh.plotting import figure\nfrom bokeh.themes import built_in_themes\nfrom bokeh.io import curdoc\nfrom bokeh.layouts import column\nimport numpy as np\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-26c7ced elementor-widget__width-initial elementor-widget elementor-widget-text-editor\" data-id=\"26c7ced\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>f<b>rom bokeh.io import output_file, show<\/b>: output_file and show are functions from the bokeh.io module that are used to save the plot to an HTML file and display the plot in the browser, respectively.<\/p><p><b>from bokeh.models import ColumnDataSource, LabelSet<\/b>: ColumnDataSource and LabelSet are classes from the bokeh.models module that are used to define the data source for the plot and add labels to the data points, respectively.<\/p><p>f<b>rom bokeh.plotting import figure<\/b>: figure is a class from the bokeh.plotting module that is used to create a new plot.<\/p><p>f<b>rom bokeh.themes import built_in_themes<\/b>: built_in_themes is a dictionary from the bokeh.themes module that contains pre-defined themes that can be used to style the plot.<\/p><p>f<b>rom bokeh.io import curdoc<\/b>: curdoc is a variable from the bokeh.io module that refers to the current document or application that is running the code.<\/p><p><b>from bokeh.layouts import column<\/b>: column is a function from the bokeh.layouts module that is used to arrange multiple plots vertically.<\/p><p>numpy is a popular numerical computing library in Python. In this code, it is used to generate random data for the scatter plot.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-3eff909 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"3eff909\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-cd769b4\" data-id=\"cd769b4\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-247c496 elementor-widget elementor-widget-menu-anchor\" data-id=\"247c496\" data-element_type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"example1\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5849795 elementor-widget elementor-widget-heading\" data-id=\"5849795\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">2- Example 1: Bokeh Scatter Plot with Python<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e287894 elementor-widget elementor-widget-text-editor\" data-id=\"e287894\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Scatter chart can be created with Bokeh using figure and scatter functions. Of course, you will need x,y data points to begin with as well. Below, we will create random data points for this chart but here are the core functions for the chart generation.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-bca9380 elementor-widget elementor-widget-html\" data-id=\"bca9380\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code># Create the figure\nfig = figure(title=\"Random Neighbors Scatter Plot\", x_axis_label=\"X\", y_axis_label=\"Y\")\n\n# Add the scatter plot\nfig.scatter(\"x\", \"y\", source=source, size=10, color=\"#FFFFFF\")\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-51b9795 elementor-widget elementor-widget-image\" data-id=\"51b9795\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"1800\" height=\"1800\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/bokeh_plot_holypython_2.png\" class=\"attachment-full size-full wp-image-31360\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/bokeh_plot_holypython_2.png 1800w, https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/bokeh_plot_holypython_2-300x300.png 300w, https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/bokeh_plot_holypython_2-1024x1024.png 1024w, https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/bokeh_plot_holypython_2-150x150.png 150w, https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/bokeh_plot_holypython_2-768x768.png 768w, https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/bokeh_plot_holypython_2-1536x1536.png 1536w, https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/bokeh_plot_holypython_2-500x500.png 500w\" sizes=\"(max-width: 1800px) 100vw, 1800px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Bokeh Scatter Chart with Python<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2c966b7 elementor-widget elementor-widget-heading\" data-id=\"2c966b7\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h5 class=\"elementor-heading-title elementor-size-default\">Saving Bokeh Charts:<\/h5>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c10b931 elementor-widget elementor-widget-text-editor\" data-id=\"c10b931\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Typically, Bokeh show function creates an html code and loads it locally in your web browser. To save your chart:<\/p><ul><li>You can save the page as html,<\/li><li>You can view page source and copy the html code manually, or<\/li><li>You can export an image by clicking on the save button on the vertical menu near the chart in browser.<\/li><\/ul><div>So, you can either save Bokeh charts as html or png images.<\/div>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c134748 elementor-widget elementor-widget-heading\" data-id=\"c134748\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h5 class=\"elementor-heading-title elementor-size-default\">Full Python Code for Bokeh Scatter Chart:<\/h5>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a35d3d2 elementor-widget elementor-widget-html\" data-id=\"a35d3d2\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from bokeh.io import output_file, show\nfrom bokeh.models import ColumnDataSource, LabelSet\nfrom bokeh.plotting import figure\nfrom bokeh.themes import built_in_themes\nfrom bokeh.io import curdoc\nfrom bokeh.layouts import column\nimport numpy as np\n\n# Set the number of data points\nn = 50\n\n# Generate random data\nx = np.random.normal(0, 1, size=n)\ny = np.random.normal(0, 1, size=n)\n\n# Create a data source\nsource = ColumnDataSource(data=dict(x=x, y=y, label=list(range(1, n+1))))\n\n# Set the output file\noutput_file(\"labeled_neighbor_scatter.html\")\n\n# Create the figure\nfig = figure(title=\"5 Random Neighbors Scatter Plot\", x_axis_label=\"X\", y_axis_label=\"Y\")\n\n# Add the scatter plot\nfig.scatter(\"x\", \"y\", source=source, size=10)\n\n# Show the plot\nshow(column(fig))\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-8a0b745 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"8a0b745\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-2fceea0\" data-id=\"2fceea0\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-fb04b53 elementor-widget elementor-widget-menu-anchor\" data-id=\"fb04b53\" data-element_type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"example2\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d06f1ac elementor-widget elementor-widget-heading\" data-id=\"d06f1ac\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">3- Example 2: Bokeh Scatter Plot with Data Labels<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c2922a1 elementor-widget elementor-widget-text-editor\" data-id=\"c2922a1\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Data labels are necessary part of visualization in many data science projects. Here we will add data labels to our chart. Let&#8217;s also utilize a theme.<\/p><p>Below we will implement <b>LabelSet<\/b> function to start adding labels with different size, position and values. Additionally, we will implement the <b>Night Sky<\/b> theme from Bokeh.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-21c7cee elementor-widget elementor-widget-html\" data-id=\"21c7cee\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code># Add labels to the data points\nlabels = LabelSet(x=\"x\", y=\"y\", text=\"label\", level=\"glyph\", source=source, text_font_size=\"10pt\", text_color=\"white\", x_offset=-5, y_offset=10)\nfig.add_layout(labels)\n\n# Set the theme to night sky\ncurdoc().theme = built_in_themes[\"night_sky\"]\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-662e778 elementor-widget elementor-widget-image\" data-id=\"662e778\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"1800\" height=\"1800\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/bokeh_scatter_plot_holypython_3.png\" class=\"attachment-full size-full wp-image-31370\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/bokeh_scatter_plot_holypython_3.png 1800w, https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/bokeh_scatter_plot_holypython_3-300x300.png 300w, https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/bokeh_scatter_plot_holypython_3-1024x1024.png 1024w, https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/bokeh_scatter_plot_holypython_3-150x150.png 150w, https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/bokeh_scatter_plot_holypython_3-768x768.png 768w, https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/bokeh_scatter_plot_holypython_3-1536x1536.png 1536w, https:\/\/holypython.com\/wp-content\/uploads\/2023\/05\/bokeh_scatter_plot_holypython_3-500x500.png 500w\" sizes=\"(max-width: 1800px) 100vw, 1800px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Bokeh Scatter Chart with Python<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-76cb800 elementor-widget elementor-widget-heading\" data-id=\"76cb800\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h5 class=\"elementor-heading-title elementor-size-default\">Saving Bokeh Charts:<\/h5>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-018ad54 elementor-widget elementor-widget-text-editor\" data-id=\"018ad54\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Typically, Bokeh show function creates an html code and loads it locally in your web browser. To save your chart:<\/p><ul><li>You can save the page as html,<\/li><li>You can view page source and copy the html code manually, or<\/li><li>You can export an image by clicking on the save button on the vertical menu near the chart in browser.<\/li><\/ul><div>So, you can either save Bokeh charts as html or png images.<\/div>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-851b717 elementor-widget elementor-widget-heading\" data-id=\"851b717\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h5 class=\"elementor-heading-title elementor-size-default\">Full Python Code for Bokeh Scatter Chart with labels:<\/h5>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-daf11c0 elementor-widget elementor-widget-html\" data-id=\"daf11c0\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from bokeh.io import output_file, show\nfrom bokeh.models import ColumnDataSource, LabelSet\nfrom bokeh.plotting import figure\nfrom bokeh.themes import built_in_themes\nfrom bokeh.io import curdoc\nfrom bokeh.layouts import column\nimport numpy as np\n\n# Set the number of data points\nn = 50\n\n# Generate random data\nx = np.random.normal(0, 1, size=n)\ny = np.random.normal(0, 1, size=n)\n\n# Create a data source\nsource = ColumnDataSource(data=dict(x=x, y=y, label=list(range(1, n+1))))\n\n# Set the output file\noutput_file(\"labeled_neighbor_scatter.html\")\n\n# Create the figure\nfig = figure(title=\"5 Random Neighbors Scatter Plot\", x_axis_label=\"X\", y_axis_label=\"Y\")\n\n# Add the scatter plot\nfig.scatter(\"x\", \"y\", source=source, size=10, color=\"#FFFFFF\")\n\n# Add labels to the data points\nlabels = LabelSet(x=\"x\", y=\"y\", text=\"label\", level=\"glyph\", source=source, text_font_size=\"10pt\", text_color=\"white\", x_offset=-5, y_offset=10)\nfig.add_layout(labels)\n\n# Set the theme to night sky\ncurdoc().theme = built_in_themes[\"night_sky\"]\n\n# Show the plot\nshow(column(fig))\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-78f04a9 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"78f04a9\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-98e0914\" data-id=\"98e0914\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-c26a5da elementor-widget elementor-widget-menu-anchor\" data-id=\"c26a5da\" data-element_type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"summary\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ad9fafb elementor-widget elementor-widget-heading\" data-id=\"ad9fafb\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Summary<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4166757 elementor-widget elementor-widget-text-editor\" data-id=\"4166757\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>In this article, we have explored the Bokeh Python library and demonstrated a simple scatter chart with labels and the Night Sky theme.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<div class=\"elementor-element elementor-element-acd0f14 elementor-widget elementor-widget-menu-anchor\" data-id=\"acd0f14\" data-element_type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"summary\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>&lt;&lt;&lt; Visualization Tutorials&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; How to create Plotly animations How to save Plotly animations How to create Mapcharts &#8211; Plotly &amp; Mapbox How to create Matplotlib animations How to save Matplotlib animations Titles, Axes, Ticks &amp; Legend Matplotlib Built-in Styles Animated Line Charts Multi-line Animation Stacked Area Charts Word Cloud Visualization Bar Chart Animations Colors with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":23147,"parent":16235,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"full-width.php","meta":{"_acf_changed":false,"footnotes":""},"class_list":["post-31306","page","type-page","status-publish","has-post-thumbnail","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/pages\/31306","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/comments?post=31306"}],"version-history":[{"count":46,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/pages\/31306\/revisions"}],"predecessor-version":[{"id":31440,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/pages\/31306\/revisions\/31440"}],"up":[{"embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/pages\/16235"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/media\/23147"}],"wp:attachment":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/media?parent=31306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}