-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDjango-App_Webpage.py
More file actions
36 lines (30 loc) · 1.01 KB
/
Django-App_Webpage.py
File metadata and controls
36 lines (30 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# data_visualization/views.py
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from django.shortcuts import render
from django.http import HttpResponse
import base64
from io import BytesIO
def plot_graph(request):
# Sample data generation using NumPy and Pandas
data = np.random.rand(100)
df = pd.DataFrame({'Data': data})
# Data visualization using Matplotlib and Seaborn
plt.figure(figsize=(10, 6))
sns.lineplot(data=df, x=df.index, y='Data')
plt.title('Random Data Trend')
plt.xlabel('Index')
plt.ylabel('Value')
# Saving plot to a buffer
buffer = BytesIO()
plt.savefig(buffer, format='png')
buffer.seek(0)
image_png = buffer.getvalue()
buffer.close()
# Encoding plot image
graphic = base64.b64encode(image_png)
graphic = graphic.decode('utf-8')
# Render the plot in a simple HTML template
return render(request, 'data_visualization/plot.html', {'graphic': graphic})