您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“Django2.2+plotly可視化數(shù)據(jù)實現(xiàn)折線圖”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細閱讀,能夠?qū)W有所成!
1 https://www.codingwithricky.com/2019/08/28/easy-django-plotly/
2 https://plotly.com/python/box-plots/
3 https://github.com/ricleal/DjangoPlotLy/tree/master/site1
這個是一個Django寫的app,值得仔細看看呀!
4 https://towardsdatascience.com/how-to-create-a-plotly-visualization-and-embed-it-on-websites-517c1a78568b
5 https://medium.com/better-programming/prettify-python-django-with-beautiful-visual-charts-836fe6646305
pip install --upgrade plotly
django-admin startproject django_plotly
cd django_plotly
python manage.py startapp boxplot
設(shè)置url 添加模板
視圖函數(shù)
rom django.shortcuts import render
from plotly.offline import plot
from plotly.graph_objs import Scatter
# Create your views here.
def index(request):
x_data = [0,1,2,3]
y_data = [x**2 for x in x_data]
data = Scatter(x=x_data,y=y_data,mode='lines',name='test',opacity=0.8,marker_color='red')
plot_div = plot([data],output_type='div')
context = {'plot_div':plot_div}
return render(request,'boxplot/index.html',context=context)
html 代碼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>簡單的折線圖</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<div class="container">
<br>
<br>
<br>
<h2 >你好嗎?</h2>
<div class="row">
<div class="col-md-8">
{{ plot_div | safe }}
</div>
</div>
<h2 >我很好!</h2>
</div>
</body>
</html>
網(wǎng)頁的呈現(xiàn)結(jié)果
“Django2.2+plotly可視化數(shù)據(jù)實現(xiàn)折線圖”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。