html - 在 html 页面中嵌入 matplotlib 条形图
问题描述
我正在尝试在 html 页面中嵌入 matplotlib 条形图。我几乎尝试了一切。这是我的代码-
意见.py-
def result(request)
plt.bar(x,h)
plt.xlabel("Personality")
plt.ylabel("course")
plt.show()
return render(request,'result.html')
解决方案
您使用plt.show()用于显示图形。如果你想在 HTML 上显示这个,你可以使用plt.savefig('my_plot.png')保存图像 并获取模板上的图像路径。
def result(request)
plt.bar(x,h)
plt.xlabel("Personality")
plt.ylabel("course")
plt.savefig('my_plot.png')
return render(request,'result.html')
结果.html
<img src='my_plot.png'>
推荐阅读
- flutter - 如何在颤动中为底部导航栏添加左滑和右滑导航?
- java - 如何从 Java 中的进程输出中实时读取 BufferedReader?
- android - Android NDK UnsatisfiedLinkError 颤动
- unix - 在 vi 编辑器模式下搜索和删除特定单词
- php - 在 php 中执行 2 个 MySql 查询(在共享主机上的 mysql 中设置时区)
- swift - 如何在 swift 4 中创建基于该 URL 重定向到特定用户配置文件的 URL?
- python - 如何在魔法中设置 Cython 语言级别
- mongodb - 使用 $lookup 和 let 和管道在 MongoDB 中声明变量
- matlab - 如何在 MATLAB 中使用 Line 或 annotation 对象绘制轴外的对象?
- go - 如何使用带有版本化 Go 模块的分叉模块(v1.11+,GO111MODULE=on)