Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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
Python 我的图像将打印为PNG,但没有显示任何内容,它在plot.show运行时显示图像_Python_Image_Matplotlib_Reportlab - Fatal编程技术网

Python 我的图像将打印为PNG,但没有显示任何内容,它在plot.show运行时显示图像

Python 我的图像将打印为PNG,但没有显示任何内容,它在plot.show运行时显示图像,python,image,matplotlib,reportlab,Python,Image,Matplotlib,Reportlab,我的代码如下。我正在使用MatPlotLib创建图像,但该图像未在png中渲染。有人,请修复我的代码,这样它将呈现 import pandas as pd import matplotlib.pyplot as plt import numpy as np #Sets the size of the chart from pylab import rcParams rcParams['figure.figsize'] = 7, 2 #AverageAnnualMedicalCostPerEE

我的代码如下。我正在使用MatPlotLib创建图像,但该图像未在png中渲染。有人,请修复我的代码,这样它将呈现

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

#Sets the size of the chart
from pylab import rcParams
rcParams['figure.figsize'] = 7, 2

#AverageAnnualMedicalCostPerEE = "{}".format('jpg')
#print AverageAnnualMedicalCostPerEE
#Creates the dataframe
raw_data = {'plan_type': ['Total Annual Cost, Single', 'Total Annual Cost,     
Family'],
        'Your Plan':     [6000, 3000],
        'Benchmark':     [4800, 1600],
        'Region':     [1800, 2800],
        'Industry':      [4900, 1300],
        'Size':      [5700, 1600],
    }

data = ['Your Plan','Benchmark','Region','Industry','Size']

df = pd.DataFrame(raw_data,
              columns = ['plan_type','Your Plan', 'Benchmark', 'Region',     
'Industry', 'Size'])

#Plots the bars, adding desired colors
ax = df.plot.bar(rot=0, color=['#ffc000',"#305496", '#8ea9db', '#b4c6e7',     
'#D9E1F2'],
             width = 0.8 )

#Adds data labels to top of bars
for p in ax.patches[0:]:
   h = p.get_height()
    x = p.get_x()+p.get_width()/2.
    if h != 0:
        ax.annotate( '$' + "%g" % p.get_height(), xy=(x,h), xytext=(0,4), 
        rotation=0,
               textcoords="offset points", ha="center", va="bottom",     
              fontsize='small', color='grey')

# Remove Bordering Frame
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['bottom'].set_color('#B4C7E7')
ax.get_xaxis().tick_bottom()
ax.get_yaxis().tick_left()

# Remove Y-axis Labels
ax.axes.get_yaxis().set_visible(False)

#Sets x-axis limits and margins
ax.set_xlim(-0.5, +1.5)
ax.margins(y=0)

# Set Y-Axis Ticks to the Right
ax.yaxis.tick_right()

# Set the Y Axis Limits
ax.set_ylim(0,(df[['Your     
Plan','Benchmark','Region','Industry','Size']].max(axis=1).max(axis=0)*1.5))
ax.margins(y=0)

#Adds legend to the top of the page
ax.legend(ncol=len(df.columns), loc="Lower Left", bbox_to_anchor=    
(0,1.02,1,0.08),
      borderaxespad=0, mode="expand",frameon=False, fontsize='small')

#Add labels to the x-axis
ax.set_xticklabels(df["plan_type"], fontsize='small')
ax.xaxis.set_ticks_position('none')
#shows the plot and prints it to
plt.show()
plt.savefig('AverageAnnualMedicalCostPerEE.png')

所以,我再次希望得到一个png,我可以稍后导入到一个表中并添加到我的故事中。后者很容易,除了图像渲染问题。请告诉我您是否可以解决此问题,可能是一个快速解决方法。

我认为您应该更改保存图像和显示图像的顺序,因为在plt.show之后,图像将重置。因此,您应该能够通过从代码中删除plt.show命令或切换plt.savefig。。。还有plt.show。

太棒了,我的下一个问题是如何将其添加到故事中?i、 e.self.appendAverage AnnualMedicalCostPeree.png