-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.py
More file actions
55 lines (44 loc) · 1.4 KB
/
default.py
File metadata and controls
55 lines (44 loc) · 1.4 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
area-basic: Basic Area Chart
Library: bokeh
"""
import pandas as pd
from bokeh.io import export_png
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
# Data
data = pd.DataFrame(
{
"month": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
"sales": [120, 135, 148, 162, 175, 195, 210, 198, 185, 170, 158, 190],
}
)
# Create x positions for categorical months
x = list(range(len(data["month"])))
y = data["sales"].tolist()
source = ColumnDataSource(data={"x": x, "y": y, "month": data["month"]})
# Create figure
p = figure(
width=4800,
height=2700,
title="Monthly Sales Volume",
x_axis_label="Month",
y_axis_label="Sales ($)",
x_range=(-0.5, len(x) - 0.5),
)
# Plot area (varea fills from y1 to y2)
p.varea(x="x", y1=0, y2="y", source=source, fill_alpha=0.7, fill_color="#306998")
# Add line on top for clearer boundary
p.line(x="x", y="y", source=source, line_width=2, line_color="#306998")
# Configure x-axis ticks to show month labels
p.xaxis.ticker = x
p.xaxis.major_label_overrides = dict(enumerate(data["month"]))
# Styling
p.title.text_font_size = "20pt"
p.xaxis.axis_label_text_font_size = "20pt"
p.yaxis.axis_label_text_font_size = "20pt"
p.xaxis.major_label_text_font_size = "16pt"
p.yaxis.major_label_text_font_size = "16pt"
p.grid.grid_line_alpha = 0.3
# Save
export_png(p, filename="plot.png")