init
This commit is contained in:
101
0_basic_chart.ipynb
Normal file
101
0_basic_chart.ipynb
Normal file
File diff suppressed because one or more lines are too long
133
1_bp_biometrik.ipynb
Normal file
133
1_bp_biometrik.ipynb
Normal file
File diff suppressed because one or more lines are too long
BIN
1_bp_biometrik.png
Normal file
BIN
1_bp_biometrik.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 189 KiB |
85
1_bp_biometrik.py
Normal file
85
1_bp_biometrik.py
Normal file
@@ -0,0 +1,85 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from matplotlib.patches import FancyBboxPatch, Rectangle
|
||||
from matplotlib.colors import LinearSegmentedColormap
|
||||
|
||||
# Color scheme
|
||||
green = '#8DC58D'
|
||||
yellow = '#FBBC78'
|
||||
red = '#F77F7F'
|
||||
gray = '#DDDDDD'
|
||||
light_blue = '#D9E8F5'
|
||||
light_gray = '#F5F5F5'
|
||||
|
||||
# Data
|
||||
categories = ["Resiko Hipertensi dalam 4 tahun (Hypertension Risk in 4 years)",
|
||||
"Lingkar Pinggang (Waist Circumference)", "Tekanan Darah Sistolik (Systolic BP)",
|
||||
"Tekanan Darah Diastolik (Diastolic BP)", "Indeks Massa Tubuh (BMI)"]
|
||||
values = [51.17, 93.0, 132.0, 88.0, 31.11]
|
||||
ranges = [(0, 100, [5, 10]), (60, 120, [80]), (70, 180, [90, 130, 140]), (50, 120, [60, 85, 90]), (15, 40, [18.5, 23, 25, 30])]
|
||||
colors = [[green, yellow, red], # Hypertension
|
||||
[green, red], # Waist
|
||||
[yellow, green, yellow, red], # Systolic BP
|
||||
[yellow, green, yellow, red], # Diastolic BP
|
||||
[yellow, green, yellow, red, red]] # BMI
|
||||
|
||||
fig, axes = plt.subplots(len(categories), 1, figsize=(12, 7))
|
||||
|
||||
for i, ax in enumerate(axes):
|
||||
min_val, max_val, thresholds = ranges[i]
|
||||
value = values[i]
|
||||
|
||||
# First create a background bar (gray) with rounded corners
|
||||
bg_rect = FancyBboxPatch((min_val, 0), max_val - min_val, 0.1,
|
||||
boxstyle="round,pad=0.01",
|
||||
facecolor=gray, alpha=0.3, linewidth=0)
|
||||
ax.add_patch(bg_rect)
|
||||
|
||||
# Create segments
|
||||
y_gap = 0.01 # Define the gap between segments on the y-axis
|
||||
ax.set_ylim(-y_gap, 0.1 + y_gap) # Adjust the y-axis limits to include the gap
|
||||
all_points = [min_val] + thresholds + [max_val]
|
||||
for j in range(len(all_points)-1):
|
||||
start = all_points[j]
|
||||
end = all_points[j+1]
|
||||
|
||||
if i == 0: # Apply gradient only for the first chart's first segment
|
||||
# Define the gradient colormap
|
||||
gradient_cmap = LinearSegmentedColormap.from_list("gradient", [gray, colors[i][j]], N=256)
|
||||
|
||||
# Create a gradient rectangle usingimshow
|
||||
gradient_width = value - start
|
||||
if gradient_width > 0:
|
||||
gradient_rect = plt.Rectangle((start, y_gap), gradient_width, 0.1 - 2*y_gap, facecolor=gradient_cmap(0.9), linewidth=0)
|
||||
ax.add_patch(gradient_rect)
|
||||
|
||||
# Fill the remaining part with gray
|
||||
remaining_width = end - max(value, start)
|
||||
if remaining_width > 0:
|
||||
remaining_rect = plt.Rectangle((max(value, start), y_gap), remaining_width, 0.1 - 2*y_gap, facecolor=gray, linewidth=0)
|
||||
ax.add_patch(remaining_rect)
|
||||
else:
|
||||
segment_width = end - start
|
||||
rect = Rectangle((start, y_gap), segment_width, 0.1 - 2*y_gap,
|
||||
facecolor=colors[i][j % len(colors[i])], linewidth=0)
|
||||
ax.add_patch(rect)
|
||||
|
||||
# Plot value marker
|
||||
ax.scatter([value], [0.06], color="white", marker="o", s=100, zorder=3, edgecolor='gray')
|
||||
ax.text(value, 0.02, f"{value:.1f}", ha="center", fontsize=10, color="black", weight="bold",
|
||||
fontfamily='monospace')
|
||||
|
||||
# Axis formatting - properly align ticks with segment boundaries
|
||||
ax.set_xlim(min_val, max_val)
|
||||
ax.set_yticks([])
|
||||
ax.set_xticks(all_points) # Set ticks at exact boundary points
|
||||
ax.set_title(categories[i], fontsize=12, weight="normal", fontfamily='sans-serif')
|
||||
ax.spines['top'].set_visible(False)
|
||||
ax.spines['right'].set_visible(False)
|
||||
ax.spines['left'].set_visible(False)
|
||||
|
||||
filename = '1_bp_biometrik.png'
|
||||
|
||||
plt.tight_layout()
|
||||
plt.savefig(filename, dpi=300, bbox_inches='tight')
|
||||
print(f"Image saved as {filename}")
|
||||
BIN
1_chart_bp_biometrik.png
Normal file
BIN
1_chart_bp_biometrik.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
BIN
1_chart_bp_biometrik_v2.png
Normal file
BIN
1_chart_bp_biometrik_v2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
104
2_urinalis.ipynb
Normal file
104
2_urinalis.ipynb
Normal file
File diff suppressed because one or more lines are too long
BIN
2_urinalis.png
Normal file
BIN
2_urinalis.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 51 KiB |
63
2_urinalis.py
Normal file
63
2_urinalis.py
Normal file
@@ -0,0 +1,63 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from matplotlib.patches import FancyBboxPatch, Rectangle
|
||||
from matplotlib.colors import LinearSegmentedColormap
|
||||
|
||||
# Color scheme
|
||||
green = '#8DC58D'
|
||||
yellow = '#FBBC78'
|
||||
red = '#F77F7F'
|
||||
gray = '#DDDDDD'
|
||||
light_blue = '#D9E8F5'
|
||||
light_gray = '#F5F5F5'
|
||||
|
||||
SEGMENT_HEIGHT = 0.1
|
||||
Y_MARKER = 0.6 * SEGMENT_HEIGHT
|
||||
Y_LABEL = 0.2 * SEGMENT_HEIGHT
|
||||
|
||||
# Data
|
||||
categories = ["pH",
|
||||
"Berat Jenis Urin (Urine Specific Gravity)"]
|
||||
values = [8.0, 1.010]
|
||||
ranges = [(0, 14, [4.8, 7.4]), (1.005, 1.030, [1.015, 1.025])]
|
||||
colors = [[yellow, green, red], # pH
|
||||
[yellow, green, red]] # Urin]
|
||||
|
||||
fig, axes = plt.subplots(len(categories), 1, figsize=(12, 2.6))
|
||||
|
||||
for i, ax in enumerate(axes):
|
||||
min_val, max_val, thresholds = ranges[i]
|
||||
value = values[i]
|
||||
|
||||
# Create segments
|
||||
# y_gap = 0.01 # {{ Removed y_gap definition }}
|
||||
ax.set_ylim(0, 0.1) # {{ Updated y-axis limits to remove y_gap }}
|
||||
all_points = [min_val] + thresholds + [max_val]
|
||||
for j in range(len(all_points)-1):
|
||||
start = all_points[j]
|
||||
end = all_points[j+1]
|
||||
segment_width = end - start
|
||||
|
||||
rect = Rectangle((start, 0), segment_width, SEGMENT_HEIGHT, # {{ Updated y-coordinate and height to remove y_gap }}
|
||||
facecolor=colors[i][j % len(colors[i])], linewidth=0)
|
||||
ax.add_patch(rect)
|
||||
|
||||
# Plot value marker
|
||||
ax.scatter([value], [Y_MARKER], color="white", marker="o", s=100, zorder=3, edgecolor='gray')
|
||||
ax.text(value, Y_LABEL, f"{value:.1f}", ha="center", fontsize=10, color="black", weight="bold",
|
||||
fontfamily='monospace')
|
||||
|
||||
# Axis formatting - properly align ticks with segment boundaries
|
||||
ax.set_xlim(min_val, max_val)
|
||||
ax.set_yticks([])
|
||||
ax.set_xticks(all_points) # Set ticks at exact boundary points
|
||||
ax.set_title(categories[i], fontsize=12, weight="bold", fontfamily='monospace')
|
||||
ax.spines['top'].set_visible(False)
|
||||
ax.spines['right'].set_visible(False)
|
||||
ax.spines['left'].set_visible(False)
|
||||
|
||||
filename = '2_urinalis.png'
|
||||
|
||||
plt.tight_layout()
|
||||
plt.savefig(filename, dpi=300, bbox_inches='tight')
|
||||
print(f"Image saved as {filename}")
|
||||
149
3_pie_suggested_lifestyle.ipynb
Normal file
149
3_pie_suggested_lifestyle.ipynb
Normal file
File diff suppressed because one or more lines are too long
BIN
3_pie_suggested_lifestyle.png
Normal file
BIN
3_pie_suggested_lifestyle.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 299 KiB |
100
3_pie_suggested_lifestyle.py
Normal file
100
3_pie_suggested_lifestyle.py
Normal file
@@ -0,0 +1,100 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
from matplotlib.patches import Rectangle
|
||||
|
||||
# Data for the pie chart
|
||||
labels = ['Tekanan Darah Sistolik', 'Berat Badan', 'Tekanan Darah Diastolik']
|
||||
en_labels = ['Systolic Blood Pressure', 'Weight', 'Diastolic Blood Pressure']
|
||||
values = [66.8, 18.9, 14.2]
|
||||
colors = ['#F77F7F', '#FFB84C', '#5ECCC4'] # Red, Orange, Teal
|
||||
|
||||
# Data for the table
|
||||
current_readings = [132, 70, 88]
|
||||
target_values = ['< 130', '41,6-51,5', '< 85']
|
||||
units = ['mmHg', 'kg', 'mmHg']
|
||||
|
||||
# Create figure with subplots
|
||||
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 10),
|
||||
gridspec_kw={'height_ratios': [1, 0.8]})
|
||||
plt.subplots_adjust(hspace=0.3)
|
||||
|
||||
# Pie Chart
|
||||
wedges, texts, autotexts = ax1.pie(values, colors=colors, autopct='',
|
||||
startangle=90, wedgeprops={'edgecolor': 'white', 'linewidth': 1})
|
||||
|
||||
# Title
|
||||
ax1.set_title('Kontributor Risiko Relatif\nRelative Risk Contributors', fontsize=16, fontweight='bold', pad=20)
|
||||
|
||||
# Add custom labels outside the pie
|
||||
for i, p in enumerate(wedges):
|
||||
ang = (p.theta2 - p.theta1)/2. + p.theta1
|
||||
ang_rad = ang * np.pi / 180
|
||||
x = 1.05 * np.cos(ang_rad)
|
||||
y = 1.05 * np.sin(ang_rad)
|
||||
|
||||
# Alignment based on angle
|
||||
horizontalalignment = 'left' if x > 0 else 'right'
|
||||
|
||||
# Create the label text with percentage and name
|
||||
label = f"{values[i]}% {labels[i]}"
|
||||
|
||||
# Add the label
|
||||
ax1.annotate(label, xy=(x, y), xytext=(1*x, 1*y),
|
||||
horizontalalignment=horizontalalignment, fontsize=12)
|
||||
|
||||
# Equal aspect ratio ensures the pie chart is circular
|
||||
ax1.set_aspect('equal')
|
||||
ax1.axis('off')
|
||||
|
||||
# Table
|
||||
# Hide axes for the table subplot
|
||||
ax2.axis('off')
|
||||
|
||||
# Create table headers
|
||||
col_labels = ['Kontributor Risiko\nRisk Contributor', 'Bacaan saat ini\nCurrent reading',
|
||||
'Nilai Target\nTarget value', 'Satuan\nUnits']
|
||||
table_data = []
|
||||
|
||||
# Prepare colored boxes for the legend
|
||||
for i, (label, en_label, value, target, unit) in enumerate(zip(labels, en_labels, current_readings, target_values, units)):
|
||||
color_box = f'\n{label}\n{en_label}'
|
||||
table_data.append([color_box, value, target, unit])
|
||||
|
||||
# Create table
|
||||
table = ax2.table(cellText=table_data, colLabels=col_labels, loc='center',
|
||||
cellLoc='center', colWidths=[0.4, 0.2, 0.2, 0.2])
|
||||
|
||||
# Format table
|
||||
table.auto_set_font_size(False)
|
||||
table.set_fontsize(10)
|
||||
table.scale(1, 2.15)
|
||||
|
||||
# Add color boxes to the first column of each data row
|
||||
for i in range(len(table_data)):
|
||||
cell = table[i+1, 0] # +1 because header is row 0
|
||||
cell.get_text().set_color('black')
|
||||
cell.set_facecolor(colors[i])
|
||||
cell.set_text_props(weight='bold')
|
||||
|
||||
# Add horizontal lines
|
||||
for i in range(len(table_data)+1):
|
||||
for j in range(len(col_labels)):
|
||||
table[i, j].set_edgecolor('black')
|
||||
|
||||
# Add risk information at the bottom
|
||||
risk_text = 'Risiko Hipertensi dalam 4 Tahun\nHypertension Risk in 4 Years'
|
||||
current_risk = '51,2 %'
|
||||
target_risk = '8,3 %'
|
||||
|
||||
ax2.text(0.00, 0.1, risk_text, transform=ax2.transAxes,
|
||||
color='red', fontsize=12, fontweight='bold')
|
||||
ax2.text(0.45, 0.15, current_risk, transform=ax2.transAxes,
|
||||
color='red', fontsize=12, fontweight='bold')
|
||||
ax2.text(0.68, 0.15, target_risk, transform=ax2.transAxes,
|
||||
color='black', fontsize=12)
|
||||
|
||||
filename = '3_pie_suggested_lifestyle.png'
|
||||
plt.tight_layout()
|
||||
plt.savefig(filename, dpi=300, bbox_inches='tight')
|
||||
print(f"Image saved as {filename}")
|
||||
Reference in New Issue
Block a user