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