Matplot图像(从PHP执行python)转换为png或sys.stdout
我试图通过在本地主机上从php脚本执行我的_task.py来保存matplot图像 我的任务.pyMatplot图像(从PHP执行python)转换为png或sys.stdout,php,python,matplotlib,apache2,Php,Python,Matplotlib,Apache2,我试图通过在本地主机上从php脚本执行我的_task.py来保存matplot图像 我的任务.py # do this before importing pylab or pyplot import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) ax.plot([1,2
# do this before importing pylab or pyplot
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot([1,2,3])
#fig.savefig('/var/www/html/test.png') # or relative path ('test.png') - Here I have an error - filename_or_obj = open(filename_or_obj, 'wb') IOError: [Errno 13] Permission denied: '/var/www/html/test.png'
print "Hello<br>"
import sys
fig.savefig(sys.stdout, type='png')
请帮助我格式化为png或使用权限来克服权限!
如何做-正确格式化png或授予权限以克服权限
以下是php代码:
<?php
$pytask = 'python py/my_task.py';
echo "<br>" .$pytask,"<br>";
$command = escapeshellcmd($pytask);
$output = shell_exec($command);
echo "<p>",$output,"</p>";
echo '<p><img src="/PyPlots/test.png" class="img-responsive img-thumbnail" alt="Куыгде"/></p>';
?>
我收到另一个错误:
无法显示图像“”,因为它包含错误
filename_or_obj = open(filename_or_obj, 'wb')
IOError: [Errno 13] Permission denied: '/var/www/html/test.png'
<?php
$pytask = 'python py/my_task.py';
echo "<br>" .$pytask,"<br>";
$command = escapeshellcmd($pytask);
$output = shell_exec($command);
echo "<p>",$output,"</p>";
echo '<p><img src="/PyPlots/test.png" class="img-responsive img-thumbnail" alt="Куыгде"/></p>';
?>
header("Content-type: image/png");