Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matplot图像(从PHP执行python)转换为png或sys.stdout_Php_Python_Matplotlib_Apache2 - Fatal编程技术网

Matplot图像(从PHP执行python)转换为png或sys.stdout

Matplot图像(从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

我试图通过在本地主机上从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,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");