Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
example kivy + python graph code
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Duncan Holmes
example kivy + python graph code
Commits
8a7f8818
Commit
8a7f8818
authored
1 month ago
by
Duncan Holmes
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
220b9c77
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
example_graph_code.py
+64
-0
64 additions, 0 deletions
example_graph_code.py
with
64 additions
and
0 deletions
example_graph_code.py
0 → 100644
+
64
−
0
View file @
8a7f8818
from
kivy.app
import
App
from
kivy.uix.image
import
Image
from
kivy.graphics.texture
import
Texture
from
kivy.uix.screenmanager
import
Screen
,
ScreenManager
from
kivy.lang
import
Builder
import
matplotlib.pyplot
as
plt
from
matplotlib.backends.backend_agg
import
FigureCanvasAgg
import
pandas
as
pd
from
io
import
BytesIO
from
PIL
import
Image
as
PILImage
class
GraphScreen
(
Screen
):
def
__init__
(
self
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
self
.
graph_texture
=
None
def
on_enter
(
self
):
# Sample CoinGecko-style data
data
=
{
"
prices
"
:
[
[
1711843200000
,
69702.31
],
[
1711929600000
,
71246.95
],
[
1711983682000
,
68887.75
]
]
}
df
=
pd
.
DataFrame
(
data
[
"
prices
"
],
columns
=
[
"
timestamp
"
,
"
price
"
])
df
[
"
timestamp
"
]
=
pd
.
to_datetime
(
df
[
"
timestamp
"
],
unit
=
"
ms
"
)
# Plot
fig
,
ax
=
plt
.
subplots
()
ax
.
plot
(
df
[
"
timestamp
"
],
df
[
"
price
"
],
label
=
"
Price
"
,
color
=
"
green
"
)
ax
.
set_title
(
"
Price Over Time
"
)
ax
.
set_xlabel
(
"
Date
"
)
ax
.
set_ylabel
(
"
Price (USD)
"
)
ax
.
legend
()
# Convert plot to Kivy texture
canvas
=
FigureCanvasAgg
(
fig
)
canvas
.
draw
()
buf
=
BytesIO
()
fig
.
savefig
(
buf
,
format
=
'
png
'
)
buf
.
seek
(
0
)
pil_image
=
PILImage
.
open
(
buf
).
transpose
(
PILImage
.
FLIP_TOP_BOTTOM
)
tex
=
Texture
.
create
(
size
=
pil_image
.
size
,
colorfmt
=
'
rgba
'
)
tex
.
blit_buffer
(
pil_image
.
convert
(
'
RGBA
'
).
tobytes
(),
colorfmt
=
'
rgba
'
,
bufferfmt
=
'
ubyte
'
)
tex
.
flip_vertical
()
# Access the image widget via ids correctly
self
.
graph_texture
=
tex
class
MyApp
(
App
):
def
build
(
self
):
return
Builder
.
load_file
(
'
example_graph_code.kv
'
)
if
__name__
==
"
__main__
"
:
app
=
MyApp
()
app
.
run
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment