{"id":5945,"date":"2020-12-09T15:18:10","date_gmt":"2020-12-09T09:48:10","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=5945"},"modified":"2023-04-30T20:54:03","modified_gmt":"2023-04-30T15:24:03","slug":"matplotlib-xticks","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/matplotlib-xticks\/","title":{"rendered":"Matplotlib xticks() in Python With Examples"},"content":{"rendered":"\n<p>In this article, we will discuss the Matplotlib xticks() in Python. Matplotlib\u00a0library in Python is a numerical \u2013 mathematical extension for NumPy library.\u00a0The Pyplot\u00a0function of this\u00a0Matplotlib\u00a0module provides a MATLAB-like interface. The matplotlib.pyplot.xticks() function is used to get or set the current tick locations and labels of the x-axis. It passes no arguments to return the current values without modifying them. Before we look into various implementations of Matplotlib xticks(), let me brief you with the syntax and return the same.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#Syntax_of_Matplotlib_xticks\" >Syntax of Matplotlib xticks()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#Parameters\" >Parameters:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#Return_Type\" >Return Type<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#Example_of_Matplotlib_xticks_in_Python\" >Example of Matplotlib xticks() in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#Matplotlib_xticks_Spacing\" >Matplotlib xticks() Spacing<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#Axis_level_xticks_frequency\" >Axis level xticks frequency<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#Rotation_of_Matplotlib_xticks_in_Python\" >Rotation of Matplotlib xticks() in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#Matplotlib_xticks_Angle\" >Matplotlib xticks Angle<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#Matplotlib_xticks_Bold\" >Matplotlib xticks Bold<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#Matplotlib_xticks_Color\" >Matplotlib xticks Color<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#How_to_set_xticks_every_10_difference\" >How to set xticks every 10 difference?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#FAQs\" >FAQs<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#Must_Read\" >Must Read<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-syntax-of-matplotlib-xticks\"><span class=\"ez-toc-section\" id=\"Syntax_of_Matplotlib_xticks\"><\/span>Syntax of Matplotlib xticks()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>matplotlib.pyplot.xticks<\/code>(ticks=None,&nbsp;labels=None,&nbsp;\\*\\*kwargs)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-parameters\"><span class=\"ez-toc-section\" id=\"Parameters\"><\/span><strong>Parameters:<\/strong> <span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>ticks<\/strong>: array-like containing the list of xtick locations. Passing an empty list removes all xticks. (Optional) <\/li>\n\n\n\n<li><strong>labels<\/strong>: array-like containing the labels to place at the given&nbsp;ticks&nbsp;locations. This argument can only be passed if&nbsp;ticks&nbsp;are passed as well. (Optional) <\/li>\n\n\n\n<li><strong>**kwargs<\/strong>: text properties that can be used to control the appearance of the labels.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-return-type\"><span class=\"ez-toc-section\" id=\"Return_Type\"><\/span>Return Type<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The Matplotlib xticks() function returns: <br><strong>locs:<\/strong> The list of xtick locations. <br><strong>labels:<\/strong> The list of xlabel <a href=\"http:\/\/www.pythonpool.com\/matplotlib-text\/\" target=\"_blank\" rel=\"noreferrer noopener\">text<\/a> objects.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-of-matplotlib-xticks-in-python\"><span class=\"ez-toc-section\" id=\"Example_of_Matplotlib_xticks_in_Python\"><\/span>Example of Matplotlib xticks() in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport math\nx = np.arange(0, math.pi*2, 0.05)\nfig = plt.figure()\nax = fig.add_axes(&#x5B;0.1, 0.1, 0.8, 0.8]) # main axes\ny = np.sin(x)\nax.plot(x, y)\nax.set_xlabel(\u2018angle\u2019)\nax.set_title('sine')\nax.set_yticks(&#x5B;-1,0,1])\nax.set_xticks(&#x5B;0,2,4,6])\nax.set_xticklabels(&#x5B;'zero','two','four','six'])\nplt.show()\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-30.png\" alt=\"Example of Matplotlib xticks() in Python\" class=\"wp-image-5946\" width=\"447\" height=\"301\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-30.png 572w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-30-300x202.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-30-150x101.png 150w\" sizes=\"(max-width: 447px) 100vw, 447px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-explanation\"><strong>Explanation:<\/strong><\/h3>\n\n\n\n<p>In the above example, an array is defined containing the xticks locations, i.e., [0, 2, 4, 6]. And that array is passed as argument to the ax.set_xticks() function. Another array is defined containing the labels to place at the tick locations i.e., [&#8216;zero&#8217;, &#8216;two&#8217;, &#8216;four&#8217;, &#8216;six&#8217;]. This array is then passed as an argument to the ax.set_xticklabels() function. Thus these two matplotlib xticks() functions as a list of xtick locations and a list of xlabel text objects.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-matplotlib-xticks-spacing\"><span class=\"ez-toc-section\" id=\"Matplotlib_xticks_Spacing\"><\/span>Matplotlib xticks() Spacing<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport matplotlib.pyplot as plt\n\nN = 100\ndata = plt.np.linspace(0, N, N)\n\nplt.plot(data)\n\nplt.xticks(range(N)) # add loads of ticks\nplt.grid()\nplt.tight_layout()\nplt.show()\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-31.png\" alt=\"Matplotlib xticks() Spacing\" class=\"wp-image-5955\" width=\"531\" height=\"349\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-31.png 694w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-31-300x197.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-31-150x99.png 150w\" sizes=\"(max-width: 531px) 100vw, 531px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-explanation-1\"><strong>Explanation:<\/strong><\/h3>\n\n\n\n<p>Firstly, in the above example, the &#8216;N&#8217; is 100 and range(N) is an argument to the plt.xticks(). As a result, the output is a list of xticks locations, and labels with very little space between them or overlapped. Thus to adjust the constant spacing, the xticks label the figure size increased by the figsize() function. Or you have to set the tick_spacing to a constant value as desired.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-axis-level-xticks-frequency\"><span class=\"ez-toc-section\" id=\"Axis_level_xticks_frequency\"><\/span>Axis level xticks frequency <span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nfig = plt.figure(figsize=(12, 6))\n\nax = fig.add_subplot(122)\n\ny = np.random.randint(low=0, high=50, size=100)\nz = np.random.randint(low=0, high=50, size=100)\n\nax.plot(y, color='black')\nax.plot(z, color='green')\n\nax.set_xticks(np.arange(0, len(x)+1, 25))\nax.set_yticks(np.arange(0, max(y), 25))\n\nplt.show()\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-33.png\" alt=\"Setting xticks() frequency\" class=\"wp-image-5957\" width=\"448\" height=\"464\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-33.png 360w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-33-290x300.png 290w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-33-150x155.png 150w\" sizes=\"(max-width: 448px) 100vw, 448px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-explanation-2\"><strong>Explanation:<\/strong><\/h3>\n\n\n\n<p>Firstly, in the above example, the xticks frequency is as per our choice. And to do so, &#8216;np.arange(0, len(x)+1, 25)&#8217; is an argument to the ax.set_xticks() function. This sets the frequency of of xticks labels to 25 i.e., the labels appear as 0, 25, 50, etc. Thus returning a list of xticks labels along the x-axis appearing at an <a href=\"https:\/\/en.wikipedia.org\/wiki\/Interval_arithmetic#:~:text=An%20interval%20can%20also%20be,complex%20numbers%20involves%20uncertain%20data.\" target=\"_blank\" rel=\"noreferrer noopener\">interval<\/a> of 25. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-rotation-of-matplotlib-xticks-in-python\"><span class=\"ez-toc-section\" id=\"Rotation_of_Matplotlib_xticks_in_Python\"><\/span>Rotation of Matplotlib xticks() in Python <span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom matplotlib import pyplot as plt\nfrom datetime import datetime, timedelta\n\nvalues = range(10)\ndates = &#x5B;datetime.now()-timedelta(days=_) for _ in range(10)]\n\nfig,ax = plt.subplots()\nplt.plot(dates, values)\nplt.xticks(rotation=45)\nplt.grid(True)\n\nplt.show()\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-32.png\" alt=\"Rotation of Matplotlib xticks() in Python\" class=\"wp-image-5956\" width=\"599\" height=\"361\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-32.png 779w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-32-300x181.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-32-768x462.png 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-32-150x90.png 150w\" sizes=\"(max-width: 599px) 100vw, 599px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-explanation-3\"><strong>Explanation:<\/strong><\/h3>\n\n\n\n<p>In the above example, a &#8216;date&#8217; array is defined containing the list of dates, which are the xticks labels for the plot.  The plt.xticks() gets or sets the properties of tick locations and labels of the x-axis. &#8216;Rotation = 45&#8217; is passed as an argument to the plt.xticks() function. Rotation is the counter-clockwise rotation angle of x-axis label text. As a result, the output is given as the xticks labels rotated by an angle o 45 degrees.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Matplotlib_xticks_Angle\"><\/span>Matplotlib xticks Angle<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We can rotate the angle of the x axis label with the help of xticks function.&nbsp;<\/p>\n\n\n\n<p>Its syntax is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>plt.xticks(rotation = n)<\/code><\/pre>\n\n\n\n<p>Here, n means the number by which you want to rotate. It can be 25,50, etc.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Matplotlib_xticks_Bold\"><\/span>Matplotlib xticks Bold<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To make xticks bold, use fontweight as bold. For example,&nbsp;<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nMyplt.xticks(fontweight='bold')\n<\/pre><\/div>\n\n\n<p>This will make the xticks bold.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Matplotlib_xticks_Color\"><\/span>Matplotlib xticks Color<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We use xticks() function to alter the colour of xticks on your plot.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nplt.xticks(color='green')\n<\/pre><\/div>\n\n\n<p>We can use any colour of our choice.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_set_xticks_every_10_difference\"><\/span>How to set xticks every 10 difference?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can set your own range using the arange function of numpy library.&nbsp; It supports float values too. Your frequency will change with this.&nbsp;<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nplt.xticks(np.arange(min(x), max(x)+1, 1.0))\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"FAQs\"><\/span>FAQs<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1682868182226\"><strong class=\"schema-faq-question\">How to use set xticks in matplotlib?<\/strong> <p class=\"schema-faq-answer\">This sets the data points in matplotlib.\u00a0<br\/>ax.set_xticks([2,4,6])<br\/>These data points will be marked on the plot now.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1682868206644\"><strong class=\"schema-faq-question\">What is the use of Xticks () and Yticks () in plotting?<\/strong> <p class=\"schema-faq-answer\">The xticks() and yticks() specify where the data points will be marked on plot.<\/p> <\/div> <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-must-read\"><span class=\"ez-toc-section\" id=\"Must_Read\"><\/span><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">Must Read<\/mark><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><a href=\"http:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/\">Matplotlib pcolormesh in Python with Examples<\/a><br><a href=\"http:\/\/www.pythonpool.com\/matplotlib-tightlayout\/\">Matplotlib tight_layout in Python with Examples<\/a><br><a href=\"http:\/\/www.pythonpool.com\/clear-plot-matplotlib\/\">How to Clear Plot in Matplotlib Using clear() Method<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we discussed various ways of implementing Matplotlib xticks() in Python programs. We learned how to set xticks labels frequency and spacing between them. And also how to rotate the xticks labels through the desired measure. We can also keep the xticks off by not passing any argument to the matplotlib xticks() function. Refer to this article for any queries related to the xticks() function.<\/p>\n\n\n\n<p>However, if you have any doubts or questions, do let me know in the comment section below. I will try to help you as soon as possible.<\/p>\n\n\n\n<p><strong><em>Happy Pythoning!<\/em><\/strong><\/p>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will discuss the Matplotlib xticks() in Python. Matplotlib\u00a0library in Python is a numerical \u2013 mathematical extension for NumPy library.\u00a0The Pyplot\u00a0function of &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Matplotlib xticks() in Python With Examples\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#more-5945\" aria-label=\"More on Matplotlib xticks() in Python With Examples\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":5991,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2071],"tags":[2660,2659,2661,2662],"class_list":["post-5945","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-matplotlib","tag-matplotlib-set-xticks","tag-matplotlib-xticks","tag-matplotlib-xticks-rotation","tag-xticks-matplotlib","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v25.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Matplotlib xticks() in Python With Examples - Python Pool<\/title>\n<meta name=\"description\" content=\"Various ways of Implementing Matplotlib xticks() in Python Programs - setting frequency, spacing and rotation of xtick labels.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Matplotlib xticks() in Python With Examples\" \/>\n<meta property=\"og:description\" content=\"In this article, we will discuss the Matplotlib xticks() in Python. Matplotlib\u00a0library in Python is a numerical \u2013 mathematical extension for NumPy\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-09T09:48:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-30T15:24:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-10.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1350\" \/>\n\t<meta property=\"og:image:height\" content=\"650\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Python Pool\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Python Pool\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/\"},\"author\":{\"name\":\"Python Pool\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998\"},\"headline\":\"Matplotlib xticks() in Python With Examples\",\"datePublished\":\"2020-12-09T09:48:10+00:00\",\"dateModified\":\"2023-04-30T15:24:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/\"},\"wordCount\":779,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-10.png\",\"keywords\":[\"matplotlib set xticks\",\"matplotlib xticks\",\"matplotlib xticks rotation\",\"xticks matplotlib\"],\"articleSection\":[\"Matplotlib\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#respond\"]}]},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/\",\"url\":\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/\",\"name\":\"Matplotlib xticks() in Python With Examples - Python Pool\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-10.png\",\"datePublished\":\"2020-12-09T09:48:10+00:00\",\"dateModified\":\"2023-04-30T15:24:03+00:00\",\"description\":\"Various ways of Implementing Matplotlib xticks() in Python Programs - setting frequency, spacing and rotation of xtick labels.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#faq-question-1682868182226\"},{\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#faq-question-1682868206644\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-10.png\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-10.png\",\"width\":1350,\"height\":650,\"caption\":\"Matplotlib xticks\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Matplotlib xticks() in Python With Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998\",\"name\":\"Python Pool\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g\",\"caption\":\"Python Pool\"}},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#faq-question-1682868182226\",\"position\":1,\"url\":\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#faq-question-1682868182226\",\"name\":\"How to use set xticks in matplotlib?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"This sets the data points in matplotlib.\u00a0<br\/>ax.set_xticks([2,4,6])<br\/>These data points will be marked on the plot now.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#faq-question-1682868206644\",\"position\":2,\"url\":\"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#faq-question-1682868206644\",\"name\":\"What is the use of Xticks () and Yticks () in plotting?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"The xticks() and yticks() specify where the data points will be marked on plot.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Matplotlib xticks() in Python With Examples - Python Pool","description":"Various ways of Implementing Matplotlib xticks() in Python Programs - setting frequency, spacing and rotation of xtick labels.","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:\/\/www.pythonpool.com\/matplotlib-xticks\/","og_locale":"en_US","og_type":"article","og_title":"Matplotlib xticks() in Python With Examples","og_description":"In this article, we will discuss the Matplotlib xticks() in Python. Matplotlib\u00a0library in Python is a numerical \u2013 mathematical extension for NumPy","og_url":"https:\/\/www.pythonpool.com\/matplotlib-xticks\/","og_site_name":"Python Pool","article_published_time":"2020-12-09T09:48:10+00:00","article_modified_time":"2023-04-30T15:24:03+00:00","og_image":[{"width":1350,"height":650,"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-10.png","type":"image\/png"}],"author":"Python Pool","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Python Pool","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-xticks\/"},"author":{"name":"Python Pool","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998"},"headline":"Matplotlib xticks() in Python With Examples","datePublished":"2020-12-09T09:48:10+00:00","dateModified":"2023-04-30T15:24:03+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-xticks\/"},"wordCount":779,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-10.png","keywords":["matplotlib set xticks","matplotlib xticks","matplotlib xticks rotation","xticks matplotlib"],"articleSection":["Matplotlib"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/matplotlib-xticks\/#respond"]}]},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/www.pythonpool.com\/matplotlib-xticks\/","url":"https:\/\/www.pythonpool.com\/matplotlib-xticks\/","name":"Matplotlib xticks() in Python With Examples - Python Pool","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-10.png","datePublished":"2020-12-09T09:48:10+00:00","dateModified":"2023-04-30T15:24:03+00:00","description":"Various ways of Implementing Matplotlib xticks() in Python Programs - setting frequency, spacing and rotation of xtick labels.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#faq-question-1682868182226"},{"@id":"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#faq-question-1682868206644"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/matplotlib-xticks\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-10.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-10.png","width":1350,"height":650,"caption":"Matplotlib xticks"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"Matplotlib xticks() in Python With Examples"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998","name":"Python Pool","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g","caption":"Python Pool"}},{"@type":"Question","@id":"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#faq-question-1682868182226","position":1,"url":"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#faq-question-1682868182226","name":"How to use set xticks in matplotlib?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"This sets the data points in matplotlib.\u00a0<br\/>ax.set_xticks([2,4,6])<br\/>These data points will be marked on the plot now.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#faq-question-1682868206644","position":2,"url":"https:\/\/www.pythonpool.com\/matplotlib-xticks\/#faq-question-1682868206644","name":"What is the use of Xticks () and Yticks () in plotting?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"The xticks() and yticks() specify where the data points will be marked on plot.","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/5945","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=5945"}],"version-history":[{"count":14,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/5945\/revisions"}],"predecessor-version":[{"id":27423,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/5945\/revisions\/27423"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/5991"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=5945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=5945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=5945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}