如何在django中绘制matplotlib(python)极坐标散点图?
How to draw a matplot lib (python) polar scatter chart in django?
我正在编写一个 Web 应用程序,我必须在其中绘制极坐标散点图 (https://matplotlib.org/examples/pie_and_polar_charts/polar_scatter_demo.html) in the webpage. The polar scatter chart is generated using python matplotlib and then is converted into JSON format and displayed on the webpage using mpld3 library(https://mpld3.github.io/install.html)。
这是我显示空极坐标散点图的代码:
<script src=".../mpld3/d3.v3.min.js"></script>
<script src=".../mpld3/mpld3.v0.3.1.dev1.min.js"></script>
<div class="col-sm-7">
<div id="fig01"></div>
<script>
mpld3.draw_figure("fig01",{"id": "el44281963893827960", "plugins": [{"type": "reset"}, {"type": "zoom", "button": true, "enabled": false}, {"type": "boxzoom", "button": true, "enabled": false}], "height": 480.0, "data": {}, "width": 640.0, "axes": [{"yscale": "linear", "id": "el44281963940408456", "axesbg": "#FFFFFF", "xdomain": [0.0, 6.283185307179586], "images": [], "xlim": [0.0, 6.283185307179586], "axesbgalpha": null, "collections": [], "ydomain": [0.0, 4.0], "markers": [], "texts": [], "xscale": "linear", "lines": [], "sharey": [], "paths": [], "axes": [{"grid": {"color": "#B0B0B0", "alpha": 1.0, "dasharray": "none", "gridOn": true}, "fontsize": 10.0, "scale": "linear", "visible": true, "nticks": 8, "position": "bottom", "tickformat": ["3", "2", "1", "8", "7", "6", "5", "4"], "tickvalues": [0.0, 0.7853981633974483, 1.5707963267948966, 2.356194490192345, 3.141592653589793, 3.9269908169872414, 4.71238898038469, 5.497787143782138]}, {"grid": {"color": "#B0B0B0", "alpha": 1.0, "dasharray": "none", "gridOn": true}, "fontsize": 10.0, "scale": "linear", "visible": true, "nticks": 4, "position": "left", "tickformat": ["Gen 1", "Gen 2", "Gen 3", ""], "tickvalues": [1.0, 2.0, 3.0, 4.0]}], "zoomable": true, "bbox": [0.22375000000000006, 0.10999999999999999, 0.5774999999999999, 0.77], "sharex": [], "ylim": [0.0, 4.0]}]} );
</script>
这里的问题是生成的图表是普通图表,而不是圆形的极坐标散点图。
这是我渲染网页后得到的:
这是我期待的地方(从 matplotlib 生成):
知道如何在我的网页中获取此圆图吗?我们将不胜感激所有建议。
有一个issue raised in 2015 for mpld3
. Since it's still an open issue, I don't think you will be able to do polar plot with mpld3
as for now. You might have to turn to alternatives like this example, using Data URI scheme可以嵌入Base64图像。
我正在编写一个 Web 应用程序,我必须在其中绘制极坐标散点图 (https://matplotlib.org/examples/pie_and_polar_charts/polar_scatter_demo.html) in the webpage. The polar scatter chart is generated using python matplotlib and then is converted into JSON format and displayed on the webpage using mpld3 library(https://mpld3.github.io/install.html)。
这是我显示空极坐标散点图的代码:
<script src=".../mpld3/d3.v3.min.js"></script>
<script src=".../mpld3/mpld3.v0.3.1.dev1.min.js"></script>
<div class="col-sm-7">
<div id="fig01"></div>
<script>
mpld3.draw_figure("fig01",{"id": "el44281963893827960", "plugins": [{"type": "reset"}, {"type": "zoom", "button": true, "enabled": false}, {"type": "boxzoom", "button": true, "enabled": false}], "height": 480.0, "data": {}, "width": 640.0, "axes": [{"yscale": "linear", "id": "el44281963940408456", "axesbg": "#FFFFFF", "xdomain": [0.0, 6.283185307179586], "images": [], "xlim": [0.0, 6.283185307179586], "axesbgalpha": null, "collections": [], "ydomain": [0.0, 4.0], "markers": [], "texts": [], "xscale": "linear", "lines": [], "sharey": [], "paths": [], "axes": [{"grid": {"color": "#B0B0B0", "alpha": 1.0, "dasharray": "none", "gridOn": true}, "fontsize": 10.0, "scale": "linear", "visible": true, "nticks": 8, "position": "bottom", "tickformat": ["3", "2", "1", "8", "7", "6", "5", "4"], "tickvalues": [0.0, 0.7853981633974483, 1.5707963267948966, 2.356194490192345, 3.141592653589793, 3.9269908169872414, 4.71238898038469, 5.497787143782138]}, {"grid": {"color": "#B0B0B0", "alpha": 1.0, "dasharray": "none", "gridOn": true}, "fontsize": 10.0, "scale": "linear", "visible": true, "nticks": 4, "position": "left", "tickformat": ["Gen 1", "Gen 2", "Gen 3", ""], "tickvalues": [1.0, 2.0, 3.0, 4.0]}], "zoomable": true, "bbox": [0.22375000000000006, 0.10999999999999999, 0.5774999999999999, 0.77], "sharex": [], "ylim": [0.0, 4.0]}]} );
</script>
这里的问题是生成的图表是普通图表,而不是圆形的极坐标散点图。
这是我渲染网页后得到的:
这是我期待的地方(从 matplotlib 生成):
知道如何在我的网页中获取此圆图吗?我们将不胜感激所有建议。
有一个issue raised in 2015 for mpld3
. Since it's still an open issue, I don't think you will be able to do polar plot with mpld3
as for now. You might have to turn to alternatives like this example, using Data URI scheme可以嵌入Base64图像。