Skip to content

Commit fe6d17d

Browse files
Add files via upload
1 parent ae2a04f commit fe6d17d

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import dearpygui.dearpygui as dpg
2+
import matplotlib
3+
matplotlib.use('Qt5Agg') # Set the backend to Qt5Agg
4+
from PyQt5 import QtCore, QtWidgets
5+
import matplotlib.pyplot as plt
6+
import numpy as np
7+
from PIL import Image
8+
9+
def update_plot(sender, app_data):
10+
x = np.linspace(0, 10, 100)
11+
y = np.sin(x)
12+
13+
plt.figure(figsize=(4, 3))
14+
plt.plot(x, y, label='Sine Wave')
15+
plt.legend()
16+
plt.tight_layout()
17+
plt.savefig('plot.png')
18+
plt.close()
19+
20+
image = Image.open('plot.png')
21+
dpg.set_value('texture', np.array(image))
22+
23+
dpg.create_context()
24+
with dpg.texture_registry():
25+
dpg.add_dynamic_texture(width=400, height=300, default_value=np.zeros((400, 300, 4)), tag="texture")
26+
27+
with dpg.window(label="Matplotlib Plot"):
28+
dpg.add_button(label="Update Plot", callback=update_plot)
29+
dpg.add_image("texture")
30+
31+
dpg.create_viewport(title='DearPyGUI with Matplotlib', width=600, height=400)
32+
dpg.setup_dearpygui()
33+
dpg.show_viewport()
34+
dpg.start_dearpygui()
35+
dpg.destroy_context()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import dearpygui.dearpygui as dpg
2+
from math import sin
3+
4+
dpg.create_context()
5+
6+
sindatax = []
7+
sindatay = []
8+
for i in range(0, 100):
9+
sindatax.append(i / 100)
10+
sindatay.append(0.5 + 0.5 * sin(50 * i / 100))
11+
sindatay2 = []
12+
for i in range(0, 100):
13+
sindatay2.append(2 + 0.5 * sin(50 * i / 100))
14+
15+
with dpg.window(label="Tutorial", width=500, height=400):
16+
# create a theme for the plot
17+
with dpg.theme(tag="plot_theme"):
18+
with dpg.theme_component(dpg.mvStemSeries):
19+
dpg.add_theme_color(dpg.mvPlotCol_Line, (150, 255, 0), category=dpg.mvThemeCat_Plots)
20+
dpg.add_theme_style(dpg.mvPlotStyleVar_Marker, dpg.mvPlotMarker_Diamond, category=dpg.mvThemeCat_Plots)
21+
dpg.add_theme_style(dpg.mvPlotStyleVar_MarkerSize, 7, category=dpg.mvThemeCat_Plots)
22+
23+
with dpg.theme_component(dpg.mvScatterSeries):
24+
dpg.add_theme_color(dpg.mvPlotCol_Line, (60, 150, 200), category=dpg.mvThemeCat_Plots)
25+
dpg.add_theme_style(dpg.mvPlotStyleVar_Marker, dpg.mvPlotMarker_Square, category=dpg.mvThemeCat_Plots)
26+
dpg.add_theme_style(dpg.mvPlotStyleVar_MarkerSize, 4, category=dpg.mvThemeCat_Plots)
27+
28+
# create plot
29+
with dpg.plot(tag="plot", label="Line Series", height=-1, width=-1):
30+
31+
# optionally create legend
32+
dpg.add_plot_legend()
33+
34+
# REQUIRED: create x and y axes
35+
dpg.add_plot_axis(dpg.mvXAxis, label="x")
36+
dpg.add_plot_axis(dpg.mvYAxis, label="y", tag="yaxis")
37+
38+
# series belong to a y axis
39+
dpg.add_stem_series(sindatax, sindatay, label="0.5 + 0.5 * sin(x)", parent="yaxis", tag="series_data")
40+
dpg.add_scatter_series(sindatax, sindatay2, label="2 + 0.5 * sin(x)", parent="yaxis", tag="series_data2")
41+
42+
# apply theme to series
43+
dpg.bind_item_theme("series_data", "plot_theme")
44+
dpg.bind_item_theme("series_data2", "plot_theme")
45+
46+
dpg.create_viewport(title='Custom Title', width=800, height=600)
47+
dpg.setup_dearpygui()
48+
dpg.show_viewport()
49+
dpg.start_dearpygui()
50+
dpg.destroy_context()

0 commit comments

Comments
 (0)