{"id":74762,"date":"2026-09-21T03:01:00","date_gmt":"2026-09-20T17:01:00","guid":{"rendered":"https:\/\/www.rjmprogramming.com.au\/ITblog\/?p=74762"},"modified":"2026-09-20T19:20:18","modified_gmt":"2026-09-20T09:20:18","slug":"python-matplotlib-pie-chart-php-crontab-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/python-matplotlib-pie-chart-php-crontab-tutorial\/","title":{"rendered":"Python Matplotlib Pie Chart PHP Crontab Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/Python\/pie_chart_python.php\" rel=\"noopener\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Python Matplotlib Pie Chart PHP Crontab Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Python\/pie_chart_python_more.gif\" title=\"Python Matplotlib Pie Chart PHP Crontab Tutorial\"  style=\"float:left;\"  \/><\/a><p class=\"wp-caption-text\">Python Matplotlib Pie Chart PHP Crontab Tutorial<\/p><\/div>\n<p>Onto yesterday&#8217;s <a title='Python Matplotlib Pie Chart Primer Tutorial' href='#pmpcpt'>Python Matplotlib Pie Chart Primer Tutorial<\/a>&#8216;s work &#8230;<\/p>\n<ul>\n<li>further to local Apache\/PHP web server, like <a target=\"_blank\" title='MAMP' href='http:\/\/www.mamp.info' rel=\"noopener\">MAMP<\/a>, PHP understanding and supervising a Python <a target=\"_blank\" title='Matplotlib: Visualization with Python' href='https:\/\/matplotlib.org\/' rel=\"noopener\">Matplotlib<\/a> module based Pie Chart web application &#8230; today &#8230;<\/li>\n<li>extending that PHP meets Python theme on the public RJM Programming we involve &#8230;\n<ol>\n<li>updated PHP &#8230; to suit the use of &#8230;<\/li>\n<li><a target=\"_blank\" title='crontab information from computerhope ... thanks' href='http:\/\/www.computerhope.com\/jargon\/c\/cron.htm' rel=\"noopener\">crontab<\/a> &#8230;<br \/>\n<code><br \/>\nksh -c 'for i in `find \/home\/rjmprogr\/public_html\/Python -name \"piechartpython_*.py\"`; do \/usr\/bin\/python3 $i ${i##*\/} \/home\/rjmprogr\/public_html\/Python\/ ; done'<br \/>\nksh -c 'for i in `find \/home\/rjmprogr\/public_html\/Python -name \"piechartpython_*.py\"`; do rm -f \"$i\"; done'<br \/>\nksh -c 'for i in `find \/home\/rjmprogr\/public_html\/Python -name \"plot_*.png\" -mmin +122`; do rm -f \"$i\"; done'<br \/>\nksh -c 'for i in `find \/home\/rjmprogr\/public_html\/Python -name \"output_image_*.png\" -mmin +122`; do rm -f \"$i\"; done'<br \/>\n<\/code><br \/>\n &#8230; means to run Python code where new arguments add image file folder and IP address personalization parts so that users do not stumble on other user Pie Chart specifications\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<p> &#8230; all still dealing with a minimalist Pie Chart we&#8217;ll add complexity to into the future with &#8230;<\/p>\n<ul>\n<li><a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/Python\/pie_chart_python.py--GETME\" rel=\"noopener\">the changed<\/a> <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/Python\/pie_chart_python.py--GETME\" rel=\"noopener\">pie_chart_python.py<\/a> Python &#8230; called via HTML form of &#8230;<\/li>\n<li><a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/Python\/pie_chart_python.php-GETME\" rel=\"noopener\">the changed<\/a> <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/Python\/pie_chart_python.php-GETME\" rel=\"noopener\">pie_chart_python.php<\/a> PHP <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/Python\/pie_chart_python.php\" rel=\"noopener\">Pie Chart<\/a> (now public) web application you can also <a href='#myifpcp'>try below<\/a><\/li>\n<\/ul>\n<p><iframe style=width:100%;height:1200px; id=myifpcp src=\"\/\/www.rjmprogramming.com.au\/Python\/pie_chart_python.php\"><\/iframe><\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=\"_blank\" href='\/\/www.rjmprogramming.com.au\/ITblog\/python-matplotlib-pie-chart-php-crontab-tutorial\/' rel=\"noopener\">Python Matplotlib Pie Chart PHP Crontab Tutorial<\/a>.<\/p-->\n<hr>\n<p id='pmpcpt'>Previous relevant <a target=\"_blank\" title='Python Matplotlib Pie Chart Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/python-matplotlib-pie-chart-primer-tutorial\/' rel=\"noopener\">Python Matplotlib Pie Chart Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/Python\/pie_chart_python.jpg\" rel=\"noopener\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Python Matplotlib Pie Chart Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Python\/pie_chart_python.gif\" title=\"Python Matplotlib Pie Chart Primer Tutorial\"  style=\"float:left;\"  \/><\/a><p class=\"wp-caption-text\">Python Matplotlib Pie Chart Primer Tutorial<\/p><\/div>\n<p>We&#8217;re off on a new discovery tour regarding &#8230;<\/p>\n<ul>\n<li>Python &#8230; as a programming language, and it&#8217;s module &#8230;<\/li>\n<li><a target=\"_blank\" title='Matplotlib: Visualization with Python' href='https:\/\/matplotlib.org\/' rel=\"noopener\">Matplotlib<\/a><\/li>\n<p> &#8230; starting down this road with a simple &#8230;<\/p>\n<ul>\n<li>command line Pie Chart application &#8230; Python <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/Python\/pie_chart_python.py-GETME\" rel=\"noopener\">pie_chart_python.py<\/a> <font size=1>(superceeding <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/Python\/pie_chart_python.py_GETME\" rel=\"noopener\">this<\/a>)<\/font> &#8230;<br \/>\n<code><br \/>\n# pie_chart_python.py<br \/>\n# September - 2026<br \/>\n# RJM Programming<br \/>\n# Thanks to https:\/\/www.w3schools.com\/python\/default.asp<br \/>\n<br \/>\nimport os<br \/>\nimport matplotlib<br \/>\n<br \/>\n# Set backend to Agg before importing pyplot<br \/>\nmatplotlib.use('Agg')<br \/>\n<br \/>\nimport matplotlib.pyplot as plt<br \/>\nimport matplotlib.image as mpimg<br \/>\n<br \/>\nimport numpy as np<br \/>\n#import plotly.express as px<br \/>\nfrom PIL import Image<br \/>\n<br \/>\nnums = []<br \/>\nsofar = 0<br \/>\n<br \/>\nif len(nums) &lt;= 0:<br \/>\n  while sofar &lt; 100:<br \/>\n     print(f\"Enter your percentage value regarding a pie chart where so far {sofar} has already been allocated.\")<br \/>\n     anum = input()<br \/>\n     nums.append(int(anum))<br \/>\n     sofar += int(anum)<br \/>\n<br \/>\ny = np.array(nums)<br \/>\n<br \/>\nfig, ax = plt.subplots()<br \/>\n<br \/>\nax.pie(y)<br \/>\n<br \/>\nfig.savefig(\"plot.png\")<br \/>\n<br \/>\n# 1. Load the image<br \/>\nimg = mpimg.imread('plot.png')<br \/>\n<br \/>\n# 2. Process or manipulate the image (Optional)<br \/>\n# For example, let's look at the shape or apply changes<br \/>\n#print(f\"Image shape: {img.shape}\")<br \/>\n<br \/>\n# 3. Create the plot without displaying it<br \/>\nplt.imshow(img)<br \/>\nplt.axis('off')  # Hide axis lines and labels<br \/>\n<br \/>\n# 4. Save the result to a file instead of showing it<br \/>\nplt.savefig('output_image.png', bbox_inches='tight', pad_inches=0)<br \/>\nplt.close()<br \/>\n<br \/>\n# Open the PNG image file<br \/>\n#with Image.open(\"plot.png\") as img:<br \/>\n    # Display the image using your system's default viewer<br \/>\n    #img.show()<br \/>\n    <br \/>\n    # Optional: Load the data into memory so you can safely close the file<br \/>\n    #img.load()<br \/>\n<br \/>\nexit()<br \/>\n<\/code><br \/>\n &#8230; and &#8230;\n<\/li>\n<li>working on our local Apache\/PHP <a target=\"_blank\" title='MAMP' href='http:\/\/www.mamp.info' rel=\"noopener\">MAMP<\/a> web server (only, so far, the reason being our public web server has no graphical $DISPLAY existant, and so the <i>plt.show()<\/i> Python codeline cannot be used, so we need to think more on integrations there) &#8230; PHP <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/Python\/pie_chart_python.php_GETME\" rel=\"noopener\">pie_chart_python.php<\/a> &#8230;<br \/>\n<code><br \/>\n&lt;?php<br \/>\n\/\/ pie_chart_python.php<br \/>\n\/\/ RJM Programming - September, 2026<br \/>\nif (php_sapi_name() === 'cli') {<br \/>\n$command = '\/usr\/local\/bin\/python3 ' . dirname(__FILE__) . DIRECTORY_SEPARATOR . 'piechartpython.py'; \/\/ Your command<br \/>\nif (1 == 1) {<br \/>\nexec($command);<br \/>\n} else {<br \/>\n\/\/ Open the process pointer for reading<br \/>\n$handle = popen($command, 'r');<br \/>\n<br \/>\nif ($handle) {<br \/>\n    \/\/ Read and output the buffer until the end of the file<br \/>\n    while (!feof($handle)) {<br \/>\n        echo fread($handle, 2048);<br \/>\n        flush(); \/\/ Send it to the browser immediately<br \/>\n    }<br \/>\n    pclose($handle);<br \/>\n}<br \/>\n}<br \/>\nexit;<br \/>\n} else if (strpos(str_replace('?','',$_SERVER['QUERY_STRING']), '&') === false) {<br \/>\n$waspy=file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'pie_chart_python.py');<br \/>\nif (strpos($waspy, \"nums = []\") !== false) {<br \/>\n    if (isset($_GET['array'])) {<br \/>\n      file_put_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'piechartpython.py', str_replace(\"nums = []\",\"nums = [\" . str_replace('+',' ',urldecode($_GET['array'])) . \"]\",$waspy));<br \/>\n    }<br \/>\n}<br \/>\n\/\/exec('php ' . dirname(__FILE__) . DIRECTORY_SEPARATOR . 'pie_chart_python.php &gt; \/dev\/null 2&gt; \/dev\/null');<br \/>\nexec('cd ' . dirname(__FILE__) . DIRECTORY_SEPARATOR . ' ; \/Applications\/MAMP\/bin\/php\/php7.4.33\/bin\/php -n .\/pie_chart_python.php &gt; \/dev\/null 2&gt; \/dev\/null ; open .\/plot.png');<br \/>\nsleep(3);<br \/>\n}<br \/>\necho \"&lt;html&gt;&lt;body style=\\\"background:url(.\/plot.png);background-repeat:no-repeat;background-size:contain;\\\"&gt;&lt;\/body&gt;&lt;\/html&gt;\";<br \/>\n?&gt;<br \/>\n<\/code>\n<\/li>\n<\/ul>\n<p> &#8230; allowing a web browser address bar URL such as &#8230;<\/p>\n<p><code><br \/>\nht<font color=black>tp<\/font>:\/\/localhost:8888\/pie_chart_python.php?array=12,5,1,68<br \/>\n<\/code><\/p>\n<p> &#8230; working for us, here, locally, displaying a Pie Chart &#8230;<\/p>\n<p><img decoding=\"async\" src=\"\/\/www.rjmprogramming.com.au\/Python\/pie_chart_python.jpg\"><\/img><\/p>\n<p> &#8230; via our local Python<sup>3<\/sup> Matplotlib modularized environment.<\/p>\n<p><b><i>Did you know?<\/i><\/b><\/p>\n<p>Your installer for Python modules is likely to be one of, for the example of <i>matplotlib<\/i> module &#8230;<\/p>\n<p><code><br \/>\npip install matplotlib<br \/>\n<\/code><\/p>\n<p> &#8230; or &#8230;<\/p>\n<p><code><br \/>\npip3 install matplotlib<br \/>\n<\/code><\/p>\n<p> &#8230; corresponding to whether command line &#8230;<\/p>\n<p><code><br \/>\npython pie_chart_python.py<br \/>\n<\/code><\/p>\n<p> &#8230; or &#8230;<\/p>\n<p><code><br \/>\npython3 pie_chart_python.py<br \/>\n<\/code><\/p>\n<p> &#8230; works for you at your local system command line.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d74751' onclick='var dv=document.getElementById(\"d74751\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/python\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d74751' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d74762' onclick='var dv=document.getElementById(\"d74762\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/crontab\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d74762' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Onto yesterday&#8217;s Python Matplotlib Pie Chart Primer Tutorial&#8216;s work &#8230; further to local Apache\/PHP web server, like MAMP, PHP understanding and supervising a Python Matplotlib module based Pie Chart web application &#8230; today &#8230; extending that PHP meets Python theme &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/python-matplotlib-pie-chart-php-crontab-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,19,37],"tags":[1885,1835,199,234,274,327,450,452,541,611,629,677,5657,802,2181,919,932,944,2550,997,1012,5658,1319],"class_list":["post-74762","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-installers","category-tutorials","tag-argument","tag-arguments","tag-chart","tag-command-line","tag-crontab","tag-did-you-know","tag-folder","tag-form","tag-graphics","tag-install","tag-ip-address","tag-korn-shell","tag-matplotlib","tag-module","tag-package-manager","tag-personalization","tag-php","tag-pie-chart","tag-pip","tag-programming","tag-python","tag-python3","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/74762"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=74762"}],"version-history":[{"count":6,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/74762\/revisions"}],"predecessor-version":[{"id":74772,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/74762\/revisions\/74772"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=74762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=74762"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=74762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}