We doubt you’ll meet many programmers not interested in “peer to peer” software suite arrangements. Thinking about Python Matplotlib module, of course, “peer to peer” becomes interesting in that the difference between the presentation of various chart types amounts to a couple of lines of Python code, in essence.
With that in mind, we think to rewrite wholly fleshed out new code file pairs consisting of …
- a Python code file specializing in creation of a display of a particular Matplotlib module chart type … supervised by a …
- a PHP supervising code file specializing in helping Python code file creation of a display of a particular Matplotlib module chart type
… for any one newly considered Matplotlib module chart type sounds like “too much hard work”. Why not add intelligence to that original Pie Chart code file pairing Python and PHP set and work off that? We came up with this idea, and it came to fruition.
And so, that is the long answer to yesterday’s question as to whether our …
strange idea
… would work?! The short answer …
Yes … the strange idea worked
… in the new workflow to getting up a new Matplotlib module chart type into the mix of our “peer to peer” web application software suite …
- clone these two crontab records …
ksh -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'
ksh -c 'for i in `find /home/rjmprogr/public_html/Python -name "piechartpython_*.py"`; do rm -f "$i"; done'
ksh -c 'for i in `find /home/rjmprogr/public_html/Python -name "plot_*.png" -mmin +122`; do rm -f "$i"; done'
ksh -c 'for i in `find /home/rjmprogr/public_html/Python -name "output_image_*.png" -mmin +122`; do rm -f "$i"; done'
… to new ones, for the example of a Column Chart …
ksh -c 'for i in `find /home/rjmprogr/public_html/Python -name "columnchartpython_*.py"`; do /usr/bin/python3 $i ${i##*/} /home/rjmprogr/public_html/Python/ ; done'
ksh -c 'for i in `find /home/rjmprogr/public_html/Python -name "columnchartpython_*.py"`; do rm -f "$i"; done'
- make the coding changes … as per …
the changed pie_chart_python.py Python … brought in a new Bar Chart …
the changed pie_chart_python.php PHP … helped bring in a new Bar Chart
… but then, thinking on it …
the changed pie_chart_python.py Python … brought in new Column and Bar Charts (in their traditional guises) …
the changed pie_chart_python.php PHP … helped bring in new Column and Bar Charts (in their traditional guises) - and then … yay!!!! … the time saver … Linux soft links to the rescue again …
cd /home/rjmprogr/public_html/Python
ln -s pie_chart_python.py bar_chart_python.py
ln -s pie_chart_python.php bar_chart_python.php
ln -s pie_chart_python.py column_chart_python.py
ln -s pie_chart_python.php column_chart_python.php
… to add onto the existant Matplotlib module Pie Chart coding, as of yesterday’s Python Matplotlib Pie Chart Labels Tutorial, interfacing now for Matplotlib module Bar Charts and Column Charts, where the logic for the new dropdown “peer to peer” links all happening via …
file naming conventions
… getting both Python and PHP to code differentiate chart types via what appears as the action URL/file name on the address bar/command line.
Feel free, as such, to try the Pie Chart++ (now public) web application you can also try below.
Previous relevant Python Matplotlib Pie Chart Labels Tutorial is shown below.
Today, further to yesterday’s Python Matplotlib Pie Chart PHP Crontab Tutorial‘s Pie Chart via Python Matplotlib “guinea pig” phase, fleshing out Pie Chart labelling …
… begging the question …
Guinea pig to what?
Do you cav
ye in?! Chortle, chortle. Well, our answer is …Cater for lots of other chart types Python Matplotlib can help interface to.
… and we have a bit of a strange idea we want to try regarding this, while today’s second “not so strange” task preparatory work was to “abstract” the term “Pie Chart” and associated phrases out of being hardcodings to be a derivative of what URL is showing in the web browser address bar. Even if our “strange idea” disappoints, and we’ll let you know tomorrow, we think, we’d want to embark on this genericization anyway, the Earth being the distance away from Mars and Venus the way it is. As such …
- the changed pie_chart_python.py Python … called via HTML form of …
- the changed pie_chart_python.php PHP Pie Chart (now public) web application you can also try below
… are definitely worth a peruse.
Previous relevant Python Matplotlib Pie Chart PHP Crontab Tutorial is shown below.
Onto yesterday’s Python Matplotlib Pie Chart Primer Tutorial‘s work …
- further to local Apache/PHP web server, like MAMP, PHP understanding and supervising a Python Matplotlib module based Pie Chart web application … today …
- extending that PHP meets Python theme on the public RJM Programming we involve …
- updated PHP … to suit the use of …
- crontab …
ksh -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'
ksh -c 'for i in `find /home/rjmprogr/public_html/Python -name "piechartpython_*.py"`; do rm -f "$i"; done'
ksh -c 'for i in `find /home/rjmprogr/public_html/Python -name "plot_*.png" -mmin +122`; do rm -f "$i"; done'
ksh -c 'for i in `find /home/rjmprogr/public_html/Python -name "output_image_*.png" -mmin +122`; do rm -f "$i"; done'
… 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
… all still dealing with a minimalist Pie Chart we’ll add complexity to into the future with …
- the changed pie_chart_python.py Python … called via HTML form of …
- the changed pie_chart_python.php PHP Pie Chart (now public) web application you can also try below
Previous relevant Python Matplotlib Pie Chart Primer Tutorial is shown below.
We’re off on a new discovery tour regarding …
- Python … as a programming language, and it’s module …
- Matplotlib
- command line Pie Chart application … Python pie_chart_python.py (superceeding this) …
# pie_chart_python.py
# September - 2026
# RJM Programming
# Thanks to https://www.w3schools.com/python/default.asp
import os
import matplotlib
# Set backend to Agg before importing pyplot
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
#import plotly.express as px
from PIL import Image
nums = []
sofar = 0
if len(nums) <= 0:
while sofar < 100:
print(f"Enter your percentage value regarding a pie chart where so far {sofar} has already been allocated.")
anum = input()
nums.append(int(anum))
sofar += int(anum)
y = np.array(nums)
fig, ax = plt.subplots()
ax.pie(y)
fig.savefig("plot.png")
# 1. Load the image
img = mpimg.imread('plot.png')
# 2. Process or manipulate the image (Optional)
# For example, let's look at the shape or apply changes
#print(f"Image shape: {img.shape}")
# 3. Create the plot without displaying it
plt.imshow(img)
plt.axis('off') # Hide axis lines and labels
# 4. Save the result to a file instead of showing it
plt.savefig('output_image.png', bbox_inches='tight', pad_inches=0)
plt.close()
# Open the PNG image file
#with Image.open("plot.png") as img:
# Display the image using your system's default viewer
#img.show()
# Optional: Load the data into memory so you can safely close the file
#img.load()
exit()
… and … - working on our local Apache/PHP MAMP web server (only, so far, the reason being our public web server has no graphical $DISPLAY existant, and so the plt.show() Python codeline cannot be used, so we need to think more on integrations there) … PHP pie_chart_python.php …
<?php
// pie_chart_python.php
// RJM Programming - September, 2026
if (php_sapi_name() === 'cli') {
$command = '/usr/local/bin/python3 ' . dirname(__FILE__) . DIRECTORY_SEPARATOR . 'piechartpython.py'; // Your command
if (1 == 1) {
exec($command);
} else {
// Open the process pointer for reading
$handle = popen($command, 'r');
if ($handle) {
// Read and output the buffer until the end of the file
while (!feof($handle)) {
echo fread($handle, 2048);
flush(); // Send it to the browser immediately
}
pclose($handle);
}
}
exit;
} else if (strpos(str_replace('?','',$_SERVER['QUERY_STRING']), '&') === false) {
$waspy=file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'pie_chart_python.py');
if (strpos($waspy, "nums = []") !== false) {
if (isset($_GET['array'])) {
file_put_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'piechartpython.py', str_replace("nums = []","nums = [" . str_replace('+',' ',urldecode($_GET['array'])) . "]",$waspy));
}
}
//exec('php ' . dirname(__FILE__) . DIRECTORY_SEPARATOR . 'pie_chart_python.php > /dev/null 2> /dev/null');
exec('cd ' . dirname(__FILE__) . DIRECTORY_SEPARATOR . ' ; /Applications/MAMP/bin/php/php7.4.33/bin/php -n ./pie_chart_python.php > /dev/null 2> /dev/null ; open ./plot.png');
sleep(3);
}
echo "<html><body style=\"background:url(./plot.png);background-repeat:no-repeat;background-size:contain;\"></body></html>";
?>
… starting down this road with a simple …
… allowing a web browser address bar URL such as …
http://localhost:8888/pie_chart_python.php?array=12,5,1,68
… working for us, here, locally, displaying a Pie Chart …

… via our local Python3 Matplotlib modularized environment.
Did you know?
Your installer for Python modules is likely to be one of, for the example of matplotlib module …
pip install matplotlib
… or …
pip3 install matplotlib
… corresponding to whether command line …
python pie_chart_python.py
… or …
python3 pie_chart_python.py
… works for you at your local system command line.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.






