python - Networkx情节在heroku中被切断
问题描述
所以我在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 片段
<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 时,我得到一个裁剪的图像
那么这里到底出了什么问题?(我如何确保图形不会被裁剪)
解决方案
事实证明这是一个graphviz问题。'neato'nx.drawing.nx_pydot.graphviz_layout(self.graph, prog='neato')
由于某种原因无法正常工作,我用它替换了它,nx.drawing.layout.spring_layout(self.graph)
并且事情按预期进行。
推荐阅读
- wordpress - 根据订单内容更改 woocommerce 客户电子邮件的回复地址
- ruby - 如何使用法拉第发送 json
- javascript - 克隆一个 4D 多维数组
- python - ValueError:没有为 Tensorflow 2.5 中的任何变量提供梯度
- angular - RXJS:创建并链接过滤器的动态数组
- nginx - DNS 问题:NXDOMAIN 为 www.exampl.com 查找 A - 检查该域是否存在 DNS 记录
- php - Codeingeter 在本地服务器中工作,但不在生活服务器中
- pine-script - pinescript中的na()函数是什么意思?
- css - 如何为具有多个配置选项的 WordPress 插件解决 CSS
- python - pd.pivot:整齐到宽数据帧转换错误