<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6170751730079448617</id><updated>2024-12-19T08:52:34.025+05:30</updated><category term="Plotting"/><category term="PythonDairies"/><category term="Visualization"/><title type='text'>Code With Rahul Bera </title><subtitle type='html'>This Blog is all about programming languages, programming, machine learning, algorithms and data structures and much more.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://codewithrahulbera.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6170751730079448617/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='https://codewithrahulbera.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Rahul</name><uri>http://www.blogger.com/profile/08868898236527675943</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6170751730079448617.post-2762308072382364910</id><published>2019-01-17T20:02:00.000+05:30</published><updated>2019-01-17T20:16:27.984+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Plotting"/><category scheme="http://www.blogger.com/atom/ns#" term="Visualization"/><title type='text'>Data Visualization in Python using Matplotlib </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5N1v-7BoWMjYFvRGrgbAT8LnxyTLaE4p02NIEfEyscz-RIg5YTmTxqnj8tsul8OSasIBFsaAFJ3jQz696Oow6vgm5sMwaU5V44-kKvgBTgFz8YDqQfuVimXv3ROHDgjTtfXhILkronn2Z/s1600/ezgif.com-gif-maker.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;logo https://realpython.com&quot; border=&quot;0&quot; data-original-height=&quot;781&quot; data-original-width=&quot;1600&quot; height=&quot;312&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5N1v-7BoWMjYFvRGrgbAT8LnxyTLaE4p02NIEfEyscz-RIg5YTmTxqnj8tsul8OSasIBFsaAFJ3jQz696Oow6vgm5sMwaU5V44-kKvgBTgFz8YDqQfuVimXv3ROHDgjTtfXhILkronn2Z/s640/ezgif.com-gif-maker.png&quot; title=&quot;Plotting&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
What is Matplotlib?&lt;/h2&gt;
&lt;div&gt;
&lt;span class=&quot;markup--strong markup--p-strong&quot; style=&quot;background-color: white; font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 21px; font-weight: 700; letter-spacing: -0.063px;&quot;&gt;&lt;em class=&quot;markup--em markup--p-em&quot; style=&quot;font-feature-settings: &#39;liga&#39; 1, &#39;salt&#39; 1;&quot;&gt;Matplotlib&lt;/em&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 21px; letter-spacing: -0.063px;&quot;&gt;&amp;nbsp;is a&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;markup--strong markup--p-strong&quot; style=&quot;background-color: white; font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 21px; font-weight: 700; letter-spacing: -0.063px;&quot;&gt;python module for creating graphs and stuff&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 21px; letter-spacing: -0.063px;&quot;&gt;,&amp;nbsp;basically for creating&lt;/span&gt;&lt;span class=&quot;markup--strong markup--p-strong&quot; style=&quot;background-color: white; font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 21px; font-weight: 700; letter-spacing: -0.063px;&quot;&gt;&amp;nbsp;Data visualizations.&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 21px; letter-spacing: -0.063px;&quot;&gt; It is the&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;markup--strong markup--p-strong&quot; style=&quot;background-color: white; font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 21px; font-weight: 700; letter-spacing: -0.063px;&quot;&gt;most popular data visualization module&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 21px; letter-spacing: -0.063px;&quot;&gt;&amp;nbsp;in python. Many other modules like&lt;/span&gt;&lt;span class=&quot;markup--strong markup--p-strong&quot; style=&quot;background-color: white; font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 21px; font-weight: 700; letter-spacing: -0.063px;&quot;&gt;&amp;nbsp;Tensorflow uses matplotlib for visualization.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;markup--strong markup--p-strong&quot; style=&quot;background-color: white; color: rgba(0 , 0 , 0 , 0.84); font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 21px; font-weight: 700; letter-spacing: -0.063px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 21px; letter-spacing: -0.063px;&quot;&gt;Installation :&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 21px; letter-spacing: -0.063px;&quot;&gt;It can be easily installed using pip command, just hit&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 21px; letter-spacing: -0.063px;&quot;&gt;&amp;nbsp; &amp;nbsp;&quot; &lt;b&gt;pip install matplotlib &quot;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 21px; letter-spacing: -0.063px;&quot;&gt;&lt;b&gt;Let&#39;s start coding Now&amp;nbsp; :&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 21px; letter-spacing: -0.063px;&quot;&gt;now we need to import our dependencies&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 21px; letter-spacing: -0.063px;&quot;&gt;and some variables&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 21px; letter-spacing: -0.063px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;script src=&quot;https://gist.github.com/bera5186/05fda74c2651b7528938c969d1015758.js&quot;&gt;&lt;/script&gt; &lt;span style=&quot;background-color: white; font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 21px; letter-spacing: -0.063px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 21px; letter-spacing: -0.063px;&quot;&gt;we imported &lt;b&gt;matplotlib.pyplot&amp;nbsp;&lt;/b&gt;API of matplotlib as plt.&amp;nbsp;We declared to python lists to plot some values. Now we Used &lt;b&gt;plt.plot() &lt;/b&gt;method to plot the points to plot. We passed two values in our case two python lists for x and y-axis values respectively. But this will not generate the plot for us, we have to use &lt;b&gt;plt.show() &lt;/b&gt;method to actually show the plot. The result of the above code is below.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 21px; letter-spacing: -0.063px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDnfLoPgr-si2xpyOYRPNDN-Hcb8MQojw0CoFZtXnBedMUoOs9wYCxHzZE7-P30Q0cQOubtn2PC4F5lzYKmR8jfo8k-IcrYD65WE1r8zFDWGP8BUkJ90E__oVzN2OmmLxbBQZOLcQRE3LF/s1600/plot1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Line Plot&quot; border=&quot;0&quot; data-original-height=&quot;576&quot; data-original-width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDnfLoPgr-si2xpyOYRPNDN-Hcb8MQojw0CoFZtXnBedMUoOs9wYCxHzZE7-P30Q0cQOubtn2PC4F5lzYKmR8jfo8k-IcrYD65WE1r8zFDWGP8BUkJ90E__oVzN2OmmLxbBQZOLcQRE3LF/s400/plot1.png&quot; title=&quot;Line Plot&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 21px; letter-spacing: -0.063px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 21px; letter-spacing: -0.063px;&quot;&gt;The output is a straight line but we can plot more complex things. In the next snippet, we will plot x^2 and x^3 values simultaneously in one plot.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 21px; letter-spacing: -0.063px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt; &lt;script src=&quot;https://gist.github.com/bera5186/19760f3a6327e2fc39ece13111a8dafd.js&quot;&gt;&lt;/script&gt; &lt;span style=&quot;font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 21px; letter-spacing: -0.063px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjroTvJ-tAeuoo1aKANNmOFnowJU1mxnqRfHCMm1aMpeBdgE8Dv6AtCBo8GD1zur5OmURUz2oGrC5IgSmYSmbs5Q6yre0wfL-AiEZ0gjn-E3PdQIj0XKb3J4vIfsFilWzz19E-SLjVE4Je7/s1600/plot2-bp2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Double plot&quot; border=&quot;0&quot; data-original-height=&quot;576&quot; data-original-width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjroTvJ-tAeuoo1aKANNmOFnowJU1mxnqRfHCMm1aMpeBdgE8Dv6AtCBo8GD1zur5OmURUz2oGrC5IgSmYSmbs5Q6yre0wfL-AiEZ0gjn-E3PdQIj0XKb3J4vIfsFilWzz19E-SLjVE4Je7/s400/plot2-bp2.png&quot; title=&quot;Double plot&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h3 style=&quot;clear: both; text-align: justify;&quot;&gt;
Scatter Plots :&lt;/h3&gt;
&lt;div style=&quot;clear: both; text-align: justify;&quot;&gt;
A graph in which the values of two variables are plotted along two axes, the pattern of the resulting points revealing any correlation present.&lt;/div&gt;
&lt;div style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjI9_Gk2FXMoD8-PbtKDun7o3q9x5mcM24LzsRpBC-k7sdh5CzEtVdT9JyQROgSV1HNOiHjWnt5pOYhtz-2Tpn4NJurqHvfVPphrdcdNbQRgtcjvr1HbY7900kYjWeQSmIyV_MZnj_XEO2e/s1600/Revenue.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Scatter&quot; border=&quot;0&quot; data-original-height=&quot;473&quot; data-original-width=&quot;981&quot; height=&quot;308&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjI9_Gk2FXMoD8-PbtKDun7o3q9x5mcM24LzsRpBC-k7sdh5CzEtVdT9JyQROgSV1HNOiHjWnt5pOYhtz-2Tpn4NJurqHvfVPphrdcdNbQRgtcjvr1HbY7900kYjWeQSmIyV_MZnj_XEO2e/s640/Revenue.png&quot; title=&quot;Scatter Example&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;clear: both; text-align: justify;&quot;&gt;
The below code snippet in an example of creating simple scatter plot in python.&lt;/div&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/bera5186/536e3a8fd7694262ff1694ea3bdfb824.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;br /&gt;
the output of the above snippet is below&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUamzPsFmlH1I1FoMGRSQwiNNRRuDoBnhIPsTQyWwAgCxtbk83xLop519ep3WZXQMeK1ybODdgzpEh25mNwMNBhyphenhyphenuTPV6smJviwZZm3QAmZepOYSDkaX0TGTqmHvlOrcZlfnQO2x6q5dvm/s1600/scatter.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Scatter plot&quot; border=&quot;0&quot; data-original-height=&quot;576&quot; data-original-width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUamzPsFmlH1I1FoMGRSQwiNNRRuDoBnhIPsTQyWwAgCxtbk83xLop519ep3WZXQMeK1ybODdgzpEh25mNwMNBhyphenhyphenuTPV6smJviwZZm3QAmZepOYSDkaX0TGTqmHvlOrcZlfnQO2x6q5dvm/s400/scatter.png&quot; title=&quot;Scatter plot&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;
&lt;/h3&gt;
&lt;h3&gt;
&lt;/h3&gt;
&lt;h3&gt;
Bar Graph :&lt;/h3&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #222222; font-family: &amp;quot;arial&amp;quot; , sans-serif; font-size: 16px; text-align: left;&quot;&gt;A&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 16px; text-align: left;&quot;&gt;bar&lt;/b&gt;&lt;span style=&quot;background-color: white; color: #222222; font-family: &amp;quot;arial&amp;quot; , sans-serif; font-size: 16px; text-align: left;&quot;&gt;&amp;nbsp;chart or&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 16px; text-align: left;&quot;&gt;bar graph&lt;/b&gt;&lt;span style=&quot;background-color: white; color: #222222; font-family: &amp;quot;arial&amp;quot; , sans-serif; font-size: 16px; text-align: left;&quot;&gt;&amp;nbsp;is a chart or&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 16px; text-align: left;&quot;&gt;graph&lt;/b&gt;&lt;span style=&quot;background-color: white; color: #222222; font-family: &amp;quot;arial&amp;quot; , sans-serif; font-size: 16px; text-align: left;&quot;&gt;&amp;nbsp;that presents categorical data with rectangular&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 16px; text-align: left;&quot;&gt;bars&lt;/b&gt;&lt;span style=&quot;background-color: white; color: #222222; font-family: &amp;quot;arial&amp;quot; , sans-serif; font-size: 16px; text-align: left;&quot;&gt;&amp;nbsp;with heights or lengths proportional to the values that they represent. The&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 16px; text-align: left;&quot;&gt;bars&lt;/b&gt;&lt;span style=&quot;background-color: white; color: #222222; font-family: &amp;quot;arial&amp;quot; , sans-serif; font-size: 16px; text-align: left;&quot;&gt;&amp;nbsp;can be plotted vertically or horizontally. A vertical&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 16px; text-align: left;&quot;&gt;bar&lt;/b&gt;&lt;span style=&quot;background-color: white; color: #222222; font-family: &amp;quot;arial&amp;quot; , sans-serif; font-size: 16px; text-align: left;&quot;&gt;&amp;nbsp;chart is sometimes called a line&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 16px; text-align: left;&quot;&gt;graph&lt;/b&gt;&lt;span style=&quot;background-color: white; color: #222222; font-family: &amp;quot;arial&amp;quot; , sans-serif; font-size: 16px; text-align: left;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #222222; font-family: &amp;quot;arial&amp;quot; , sans-serif; font-size: 16px; text-align: left;&quot;&gt;The below snippet shows how to create a simple bar graph in python.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/bera5186/ce8c72229707483ffd40fb29f7fa5875.js&quot;&gt;&lt;/script&gt; &lt;b&gt;Output :&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmV8ibPjOzIOE7Bx5u_0o0A6VtfM0CF5S7cgQA_z_CYnbQsfSRgpr2WSlhMy65ca0bjrof0LA2VGHkgXtJSIoWwv5QI5rP1hlRxGC586ti6kn3FT1Iw3EaL5S52lbtMGxmVgaLExzsRELT/s1600/bar.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Bar chart&quot; border=&quot;0&quot; data-original-height=&quot;576&quot; data-original-width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmV8ibPjOzIOE7Bx5u_0o0A6VtfM0CF5S7cgQA_z_CYnbQsfSRgpr2WSlhMy65ca0bjrof0LA2VGHkgXtJSIoWwv5QI5rP1hlRxGC586ti6kn3FT1Iw3EaL5S52lbtMGxmVgaLExzsRELT/s400/bar.png&quot; title=&quot;Bar chart&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;clear: both; text-align: justify;&quot;&gt;
Pie Chart in Python :&lt;/h3&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; font-style: italic; letter-spacing: -0.063px;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;An Emma chart (or a circle chart) is a circular statistical graphic which is divided into slices to illustrate numerical proportion. In a pie chart, the arc length of each slice (and consequently its central angle and area), is proportional to the quantity it represents.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; font-style: italic; letter-spacing: -0.063px;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; font-style: italic; letter-spacing: -0.063px;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;The below code snippet shows how to create a&amp;nbsp;simple pie chart in python :&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/bera5186/d4a587ce616e44c9fa5cc04e45563ca9.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;background-color: white; letter-spacing: -0.063px;&quot;&gt;&lt;i&gt;For pie charts &lt;b&gt;plt.pie()&amp;nbsp;&lt;/b&gt;&amp;nbsp;method is used. The first parameter is the values to be plotted in our&amp;nbsp;case a list. Next parameter is the label of the plotted values. The &lt;b&gt;autopct&amp;nbsp;&lt;/b&gt;parameter is to specify to show the percentage in the chart.&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-style: italic; letter-spacing: -0.063px;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt; &lt;span style=&quot;background-color: white; font-style: italic; letter-spacing: -0.063px;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;output :&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1ZdXy_yq0fL_26Ei_T_wSN0wPEU8Y2gGdYjhSURCrhOmUGHHHT1o0dqUrdEt2jBpvGF97HGjnBOCujpNefgaIQelNiK3orCruRiS4FdmSAjyLm2tYfQ-3lyFrajs3EODY6jotAQilMzH5/s1600/pie.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;PIE chart&quot; border=&quot;0&quot; data-original-height=&quot;576&quot; data-original-width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1ZdXy_yq0fL_26Ei_T_wSN0wPEU8Y2gGdYjhSURCrhOmUGHHHT1o0dqUrdEt2jBpvGF97HGjnBOCujpNefgaIQelNiK3orCruRiS4FdmSAjyLm2tYfQ-3lyFrajs3EODY6jotAQilMzH5/s400/pie.png&quot; title=&quot;PIE chart&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; font-style: italic; letter-spacing: -0.063px;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;
&lt;b&gt;Now I covered most common types of charts in matplotlib. Let&#39;s have a question-answer round ;)&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;h4 style=&quot;clear: both; text-align: justify;&quot;&gt;
Q: How do I turn on grid in the plot?&lt;/h4&gt;
&lt;div&gt;
soln: Just add a line &lt;b&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;plt.grid(True)&lt;/span&gt;.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjP040VTz-739yDrZ9EuAVugxYAbLG1tRfdLVR-zX_Y6eSXE1f4D_qakFKQ7R61jnudSQHvvmMyRkPCifnIkHnNB2Hw9DQ5O6sW5wruJtxkVj-DqrwoyIuaef5-IHxusxdNzjCa6KdwqqCp/s1600/grid.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Grid On&quot; border=&quot;0&quot; data-original-height=&quot;576&quot; data-original-width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjP040VTz-739yDrZ9EuAVugxYAbLG1tRfdLVR-zX_Y6eSXE1f4D_qakFKQ7R61jnudSQHvvmMyRkPCifnIkHnNB2Hw9DQ5O6sW5wruJtxkVj-DqrwoyIuaef5-IHxusxdNzjCa6KdwqqCp/s400/grid.png&quot; title=&quot;Grid On&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h4 style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;em class=&quot;markup--em markup--p-em&quot; style=&quot;color: rgba(0, 0, 0, 0.84); font-family: medium-content-serif-font, Georgia, Cambria, &amp;quot;Times New Roman&amp;quot;, Times, serif; font-feature-settings: &#39;liga&#39; 1, &#39;salt&#39; 1; font-weight: 700; letter-spacing: -0.063px;&quot;&gt;Q: How do I change my line colours/width/style?&lt;/em&gt;&lt;/h4&gt;
&lt;div&gt;
&lt;em class=&quot;markup--em markup--p-em&quot; style=&quot;font-weight: 700; letter-spacing: -0.063px;&quot;&gt;soln:&amp;nbsp;&lt;/em&gt;&lt;span style=&quot;background-color: white; font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; letter-spacing: -0.003em;&quot;&gt;You can pass in the arguments colour, linewidth, and linestyle.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: rgba(0 , 0 , 0 , 0.05); font-family: &amp;quot;menlo&amp;quot; , &amp;quot;monaco&amp;quot; , &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: rgba(0 , 0 , 0 , 0.05); font-family: &amp;quot;menlo&amp;quot; , &amp;quot;monaco&amp;quot; , &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;plt.plot(x, y, color = ‘green’ , linewidth = 2, linestyle = “-”)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: rgba(0 , 0 , 0 , 0.05); color: rgba(0 , 0 , 0 , 0.84); font-family: &amp;quot;menlo&amp;quot; , &amp;quot;monaco&amp;quot; , &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjFqsI1bBj5WF6dXOPm4-XtQW1PhrghTay6VEvxYVnjFH4NHyx6f0qeisFLyKmR5WeptZ6Tgp4EBy4f2qLd3dO4HMBxf-iPHKLd3ZwNyMD7VIHkQTpEz8rEFsuAqEskw1fMZvrBIiG3mrQ/s1600/linestyke.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Line style&quot; border=&quot;0&quot; data-original-height=&quot;576&quot; data-original-width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjFqsI1bBj5WF6dXOPm4-XtQW1PhrghTay6VEvxYVnjFH4NHyx6f0qeisFLyKmR5WeptZ6Tgp4EBy4f2qLd3dO4HMBxf-iPHKLd3ZwNyMD7VIHkQTpEz8rEFsuAqEskw1fMZvrBIiG3mrQ/s400/linestyke.png&quot; title=&quot;Line style&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;markup--strong markup--p-strong&quot; style=&quot;background-color: white; font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-weight: 700; letter-spacing: -0.063px;&quot;&gt;&lt;em class=&quot;markup--em markup--p-em&quot; style=&quot;font-feature-settings: &#39;liga&#39; 1, &#39;salt&#39; 1;&quot;&gt;Q: How do I change the transparency for my lines?&lt;/em&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;span class=&quot;markup--strong markup--p-strong&quot; style=&quot;background-color: white; font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-weight: 700; letter-spacing: -0.063px;&quot;&gt;&lt;em class=&quot;markup--em markup--p-em&quot; style=&quot;font-feature-settings: &#39;liga&#39; 1, &#39;salt&#39; 1;&quot;&gt;soln:&amp;nbsp;&lt;/em&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; letter-spacing: -0.063px;&quot;&gt;Pass in the alpha parameter to your plot. Alpha can be set from 0 to 1, where 0 is completely transparent and 1 is no transparency.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: rgba(0 , 0 , 0 , 0.05); font-family: &amp;quot;menlo&amp;quot; , &amp;quot;monaco&amp;quot; , &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: rgba(0 , 0 , 0 , 0.05); font-family: &amp;quot;menlo&amp;quot; , &amp;quot;monaco&amp;quot; , &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;plt.plot(x, y, alpha = 0.1)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1rcxLHQoLvezwmgh7mtxpPwgbmiMm7nv5wS1YAWSopjFBSPDw8_N8m8C3mNuNz-W9tuZER6NZ7DyF6Bau-eZOEOf_FEfrV3_3BSoyNSKhwk-n0EiWLcOJyjPJ5UUQv005HtL9LgcmF8Og/s1600/alpha.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;alpha property&quot; border=&quot;0&quot; data-original-height=&quot;576&quot; data-original-width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1rcxLHQoLvezwmgh7mtxpPwgbmiMm7nv5wS1YAWSopjFBSPDw8_N8m8C3mNuNz-W9tuZER6NZ7DyF6Bau-eZOEOf_FEfrV3_3BSoyNSKhwk-n0EiWLcOJyjPJ5UUQv005HtL9LgcmF8Og/s400/alpha.png&quot; title=&quot;alpha property&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: rgba(0 , 0 , 0 , 0.84); font-family: , &amp;quot;georgia&amp;quot; , &amp;quot;cambria&amp;quot; , &amp;quot;times new roman&amp;quot; , &amp;quot;times&amp;quot; , serif; font-size: 21px; letter-spacing: -0.003em;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Bonus: Live Plot Your CPU usage Using Matplotlib and python&lt;/h2&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhF5FNu_OUnE75RKqEN1TAekjVucybwK3C50BbUFCkXjWkG61MlAfwZNR-TJOMHZFQbsdFGS7sFC5l0z6rru9fGMawRyJ_g00kC7ol5FT_EVwlcfqvPL9qwYKkJFC7HtJ6-Zeq8Bve2fyNs/s1600/ezgif.com-optimize+%25281%2529.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;CPU Usage&quot; border=&quot;0&quot; data-original-height=&quot;401&quot; data-original-width=&quot;600&quot; height=&quot;425&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhF5FNu_OUnE75RKqEN1TAekjVucybwK3C50BbUFCkXjWkG61MlAfwZNR-TJOMHZFQbsdFGS7sFC5l0z6rru9fGMawRyJ_g00kC7ol5FT_EVwlcfqvPL9qwYKkJFC7HtJ6-Zeq8Bve2fyNs/s640/ezgif.com-optimize+%25281%2529.gif&quot; title=&quot;CPU Usage&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/bera5186/7b0429e5680de2c26cf883d84ef8c9b6.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
For getting&amp;nbsp;CPU usage I used &lt;b&gt;psutil&amp;nbsp;python &lt;/b&gt;module. The &lt;b&gt;cpu_percent() &lt;/b&gt;function returns me current CPU usage.&lt;br /&gt;
&lt;b style=&quot;background-color: #cccccc;&quot;&gt;%matplotlib notebook&lt;/b&gt;&lt;br /&gt;
&lt;b style=&quot;background-color: #cccccc;&quot;&gt;plt.rcParams[&#39;animation.html&#39;] = &#39;jshtml&#39;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;These two lines are for rendering the plot with javascript. I wrapped all this around a while loop and kept updating the plot each and every time.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt; &lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt; &lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt; &lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;Please subscribe to the blog for more programming content. If you have doubt regarding the post a comment.&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;Previuos post : How to create a CLI dictionary in python&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://codewithrahulbera.blogspot.com/2019/01/blog-post_54.html&quot; target=&quot;_blank&quot;&gt;https://codewithrahulbera.blogspot.com/2019/01/blog-post_54.html&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://codewithrahulbera.blogspot.com/feeds/2762308072382364910/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://codewithrahulbera.blogspot.com/2019/01/Data-Visualization-in-Python-using-Matplotlib.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6170751730079448617/posts/default/2762308072382364910'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6170751730079448617/posts/default/2762308072382364910'/><link rel='alternate' type='text/html' href='https://codewithrahulbera.blogspot.com/2019/01/Data-Visualization-in-Python-using-Matplotlib.html' title='Data Visualization in Python using Matplotlib '/><author><name>Rahul</name><uri>http://www.blogger.com/profile/08868898236527675943</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5N1v-7BoWMjYFvRGrgbAT8LnxyTLaE4p02NIEfEyscz-RIg5YTmTxqnj8tsul8OSasIBFsaAFJ3jQz696Oow6vgm5sMwaU5V44-kKvgBTgFz8YDqQfuVimXv3ROHDgjTtfXhILkronn2Z/s72-c/ezgif.com-gif-maker.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6170751730079448617.post-6080436628374777826</id><published>2019-01-11T15:39:00.001+05:30</published><updated>2019-01-12T10:10:31.664+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="PythonDairies"/><title type='text'>Let&#39;s Code a CLI-Dictionary in Python</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOpbtl0wYUV12PCTpEFzf6rqIgxDXKkEI42vWjtsPU86YMZ53iMs6D3svWPweWXNiWR9Onp9evv_X8pkbpPuskcGQte_biUEgTNvIFTCkwTgfujJNnS3bbp3GlaNAynTqXXcizQomoSROE/s1600/hitesh-choudhary-666995-unsplash.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;900&quot; data-original-width=&quot;1600&quot; height=&quot;360&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOpbtl0wYUV12PCTpEFzf6rqIgxDXKkEI42vWjtsPU86YMZ53iMs6D3svWPweWXNiWR9Onp9evv_X8pkbpPuskcGQte_biUEgTNvIFTCkwTgfujJNnS3bbp3GlaNAynTqXXcizQomoSROE/s640/hitesh-choudhary-666995-unsplash.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;From past years python has grown its popularity. Some of the reasons being:&amp;nbsp;&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Python Is backed by a large community.&lt;/li&gt;
&lt;li&gt;Python has great corporate sponsors. One of them is Google.&lt;/li&gt;
&lt;li&gt;Python has amazing library for almost everything. You can look a theme&amp;nbsp;&lt;a href=&quot;https://github.com/vinta/awesome-python&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;It can be used for big data and cloud services at the enterprise level.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Now let&#39;s start coding&amp;nbsp;&lt;/h2&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
This is what we are going to build&amp;nbsp;&lt;/h4&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2J1_pcHW2kovu3-IERl1zKFvo-XFAD29IPKigkEc5pTIyI7ycd_sCGOcuEXzdujws8TXWbdLbHYKUY83KFI67edzI0oeXSVyeY03V4KqWHKuZ_kjC8MeUn2cUZG-PIcGopSDU4Stz7jkY/s1600/ezgif.com-optimize.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;400&quot; data-original-width=&quot;600&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2J1_pcHW2kovu3-IERl1zKFvo-XFAD29IPKigkEc5pTIyI7ycd_sCGOcuEXzdujws8TXWbdLbHYKUY83KFI67edzI0oeXSVyeY03V4KqWHKuZ_kjC8MeUn2cUZG-PIcGopSDU4Stz7jkY/s1600/ezgif.com-optimize.gif&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&amp;nbsp;These are our imports&lt;/div&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/bera5186/cc913ddbbbf53faf7780fe49876a817b.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;b&gt;requests:&lt;/b&gt;&amp;nbsp;Library for handling HTTP requests or simply getting&amp;nbsp;a response&amp;nbsp;from the website.&amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;bs4:&amp;nbsp;&lt;/b&gt;&amp;nbsp;It&#39;s a python library for parsing HTML tags from the source we get from requests.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;sys: &lt;/b&gt;It&#39;s basically a built-in library which I used for parsing&lt;b&gt;&lt;/b&gt; the command line arguments.&amp;nbsp; &amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
The working of our dictionary will be online i.e it will work only when you are connected to the internet. Our code will scrape the definition of the given word from an online dictionary named dictionary.com.&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/bera5186/a2ade940f1b449983ac4b9b7c2ca4546.js&quot;&gt;&lt;/script&gt; Now I created a variable called &lt;b&gt;base_url&lt;/b&gt; which will hold the URL for the website and added an exception handling block to check if the word is provided or not. Here &lt;b&gt;querry &lt;/b&gt;variable holds&lt;br /&gt;
&lt;b&gt;sys.argv[1]&amp;nbsp;&lt;/b&gt;&amp;nbsp;will give us the first word given in the argument.&lt;br /&gt;
&lt;br /&gt;
Again I added a try/except block in which I used &lt;b&gt;requests.get() &lt;/b&gt;method which takes a URL as an argument and returns a response. If it doesn&#39;t get a response then it prompts the user to check internet&amp;nbsp;connection.&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/bera5186/063f3ddd1a5a9fa221984aaa62934a5e.js&quot;&gt;&lt;/script&gt; Now I created a &lt;b&gt;soup&lt;/b&gt; object by passing it two arguments :&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;b&gt;r.content:&lt;/b&gt;&amp;nbsp;It is the complete source code of the website we get as a response.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;html.parser: &lt;/b&gt;It is the parser which will parse the HTML tags for us from the page source.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
Now open&amp;nbsp;&lt;a href=&quot;http://dictionary.com/browse/apple&quot; target=&quot;_blank&quot;&gt;dictionary.com&lt;/a&gt;&amp;nbsp;and search for apple.&amp;nbsp;It shows up like this&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCuVBAsagcyusc1uO8tHfmoZTEoXvMVjQrjPy2wc4GUi18s7y7Y9n3ySJ455c01QDstRY7NSVQ5VA8uj3XQzg-yfnOl0dl7GDUbPSzR_KQW9SF_82Z2WzzdqfR-rUunDvHA8JW8vPD1yES/s1600/bp11.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;838&quot; data-original-width=&quot;1118&quot; height=&quot;478&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCuVBAsagcyusc1uO8tHfmoZTEoXvMVjQrjPy2wc4GUi18s7y7Y9n3ySJ455c01QDstRY7NSVQ5VA8uj3XQzg-yfnOl0dl7GDUbPSzR_KQW9SF_82Z2WzzdqfR-rUunDvHA8JW8vPD1yES/s640/bp11.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
We are interested in getting the noun tag and the definitions are given&amp;nbsp;for the word. Now to scrape we have to inspect the elements.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmuHlkFPpemAPFTDGp7oXWvKwlCZM0l1LXED3lIpdFOn5kv4RkdRP0GxEAyTjHvkI4Bmn4zWfCZBXh-hbBJy-ILbWm4BZsvvzGrd33ocugAADcsi0KuSshhjprxgdEkAcM5jsXGCDQBkl2/s1600/bp12.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;350&quot; data-original-width=&quot;737&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmuHlkFPpemAPFTDGp7oXWvKwlCZM0l1LXED3lIpdFOn5kv4RkdRP0GxEAyTjHvkI4Bmn4zWfCZBXh-hbBJy-ILbWm4BZsvvzGrd33ocugAADcsi0KuSshhjprxgdEkAcM5jsXGCDQBkl2/s1600/bp12.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
The noun tag is bounded by a span of class&amp;nbsp;luna-pos.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZ4vAA6s2D0VMW9NeBF7CUMDxxEAWTpsJTDGFsIOHZT9iM_D0CiyLmbi_cTmDT2j8L4qvUXJr3Q-O_ynpj-HTDRSFxJWoR9LxLb4o8RGVjsh7F4A8nfgtm2eUutla4TBhe2SYStpyNenbg/s1600/bp13.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;347&quot; data-original-width=&quot;912&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZ4vAA6s2D0VMW9NeBF7CUMDxxEAWTpsJTDGFsIOHZT9iM_D0CiyLmbi_cTmDT2j8L4qvUXJr3Q-O_ynpj-HTDRSFxJWoR9LxLb4o8RGVjsh7F4A8nfgtm2eUutla4TBhe2SYStpyNenbg/s1600/bp13.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
And the definitions are in an ordered&amp;nbsp;list in which the items are as a list item.&lt;br /&gt;
&lt;br /&gt;
So I defined a variable call &lt;b&gt;adj &lt;/b&gt;which will hold the adjective or noun tag. For this, I used the &lt;b&gt;soup.find() method. &lt;/b&gt;Its first argument is the tag you want to find, for this case &lt;b&gt;&#39;span&#39;&amp;nbsp;&lt;/b&gt;and the second argument is a dictionary which defines it&#39;s attributed in this case it&#39;s class &lt;b&gt;&#39;luna-pos&#39;&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
For finding the definitions I used &lt;b&gt;soup.findAll() &lt;/b&gt;method and passed &lt;b&gt;&quot;ol&quot; &lt;/b&gt;as an argument to get all the content of ol tag and stored it in a variable called definitions. To find the elements inside it i.e the &quot;&lt;b&gt;li&lt;/b&gt;&quot; tags I used findchildren() method and set &lt;b&gt;&quot;recursive=False&quot;&lt;/b&gt;&amp;nbsp;so that it doesn&#39;t find&amp;nbsp;the child of the child.&lt;br /&gt;
Lastly, I wrapped all this around a try/except block for exception handling if the code is not able to get these html tags then it will simply print &quot;Word Not found&quot; and exit.&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/bera5186/76c83b98933d46e14d12dab71e700c8e.js&quot;&gt;&lt;/script&gt; At last, I printed out the word and the adjective(tag) for the word and iterated over the meanings scraped and printed them out. Let&#39;s run the code ;)&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimbff6i4YnrA7wxLOGLnvOZuwCYPp7V83W61PSfItTpU3DehaP5vfE1vlVuVtAxpMrvpCsiyKLD3KxYyq8C9VjQR6E3rK-mwt0hm6GSYiN2NjJOTTjnPjgrgLBbrJDpBEM_a8V6CL0-xKf/s1600/bp14.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;249&quot; data-original-width=&quot;988&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimbff6i4YnrA7wxLOGLnvOZuwCYPp7V83W61PSfItTpU3DehaP5vfE1vlVuVtAxpMrvpCsiyKLD3KxYyq8C9VjQR6E3rK-mwt0hm6GSYiN2NjJOTTjnPjgrgLBbrJDpBEM_a8V6CL0-xKf/s1600/bp14.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
To make it available&amp;nbsp;everywhere in your terminal do the following :&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Open .bashrc&amp;nbsp;file .&lt;/li&gt;
&lt;li&gt;add &quot;&lt;b&gt;alias define=&quot;~/path_to_your_python_script&lt;/b&gt;&quot; and save.&lt;/li&gt;
&lt;li&gt;From terminal now run &quot;&amp;nbsp;&lt;b&gt;source ~/.bashrc&lt;/b&gt; &quot;.&lt;/li&gt;
&lt;li&gt;Now you can use &quot; &lt;b&gt;define word-to-search&lt;/b&gt; &quot; anywhere in&amp;nbsp;terminal.&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0b8RgAvtukvsJAuRqwLklisKzhfZ6jGsKVzQzjpxybM2YFrrMzpRWyITTFKNt1c4VHsQczkxv-BJQKLjMxdju5N_lr5ENmnSo5qY6xw0mT6zsCnNBO7P07nkc3OynywMABLiyLCUoq9P3/s1600/bp16.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;406&quot; data-original-width=&quot;756&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0b8RgAvtukvsJAuRqwLklisKzhfZ6jGsKVzQzjpxybM2YFrrMzpRWyITTFKNt1c4VHsQczkxv-BJQKLjMxdju5N_lr5ENmnSo5qY6xw0mT6zsCnNBO7P07nkc3OynywMABLiyLCUoq9P3/s1600/bp16.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='https://codewithrahulbera.blogspot.com/feeds/6080436628374777826/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://codewithrahulbera.blogspot.com/2019/01/blog-post_54.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/6170751730079448617/posts/default/6080436628374777826'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/6170751730079448617/posts/default/6080436628374777826'/><link rel='alternate' type='text/html' href='https://codewithrahulbera.blogspot.com/2019/01/blog-post_54.html' title='Let&#39;s Code a CLI-Dictionary in Python'/><author><name>Rahul</name><uri>http://www.blogger.com/profile/08868898236527675943</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOpbtl0wYUV12PCTpEFzf6rqIgxDXKkEI42vWjtsPU86YMZ53iMs6D3svWPweWXNiWR9Onp9evv_X8pkbpPuskcGQte_biUEgTNvIFTCkwTgfujJNnS3bbp3GlaNAynTqXXcizQomoSROE/s72-c/hitesh-choudhary-666995-unsplash.jpg" height="72" width="72"/><thr:total>4</thr:total></entry></feed>