【发布时间】:2021-10-14 19:02:38
【问题描述】:
所以我在 heroku 上部署了一个 django 应用程序。它创建了一个 networkx 图。
这个函数基本上是做绘图并返回base64图像。
def draw(self, plot=False):
self.compile() # creates the self.graph using list of edges
fig, ax = plt.subplots(figsize=(6, 4.5))
nx.draw_networkx(self.graph,
pos=self.pos,
node_color=self.node_color,
node_size=self.node_size,
edgecolors=self.edgecolors,
edge_color=self.edge_color,
width=1.5,
ax=ax)
ax.set_xlim([2 * x for x in ax.get_xlim()])
ax.set_ylim([2 * y for y in ax.get_ylim()])
if plot:
plt.show()
buffer = BytesIO()
plt.savefig(buffer, format='png', bbox_inches="tight")
plt.close()
img64 = base64.b64encode(buffer.getvalue()).decode("utf-8").replace("\n", "")
return img64
Html sn-p
<div id="section2" class="section">
<div id="table_div" class="row">
<div class="col s12 center-align">
<!--- TABLE TEMPLATE -->
{% if image != None %}
<div class="card-panel">
<img id="img" src="data:image/png;base64,{{ image }}"\>
</div>
{% endif %}
</div>
</div>
</div>
但是,当我将它部署到 heroku 时,我得到一个裁剪的图像
那么这里到底出了什么问题? (如何确保图不会被裁剪)
【问题讨论】:
标签: python matplotlib heroku networkx