Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set plot marker with custom color dict by using add_theme_color #2395

Open
tonyzhangnxp opened this issue Sep 29, 2024 · 3 comments
Open

Set plot marker with custom color dict by using add_theme_color #2395

tonyzhangnxp opened this issue Sep 29, 2024 · 3 comments
Labels
state: pending not addressed yet

Comments

@tonyzhangnxp
Copy link

Hello there

The API add_theme_color supports color dict as input, but it doesn't work.
Here is the code

import random
import dearpygui.dearpygui as dpg
dpg.create_context()

with dpg.theme() as plot_theme:
    with dpg.theme_component(dpg.mvScatterSeries):
        marker_size = dpg.add_theme_style(dpg.mvPlotStyleVar_MarkerSize, 1, category=dpg.mvThemeCat_Plots)
        color_dict = []
        for i in range(10):
            if i %2 == 1:
                color_dict.append((255,0,0,255))
            else:
                color_dict.append((0,255,0,255))
        dpg.add_theme_color(dpg.mvPlotCol_MarkerFill, value=color_dict, category=dpg.mvThemeCat_Plots)



def change_marker_size(_, app_data):
    dpg.set_value(marker_size, [app_data])

with dpg.window():
    dpg.add_slider_int(label="Marker Size", min_value=1, max_value=10, default_value=1, callback=change_marker_size)
    with dpg.plot():
        dpg.add_plot_legend()
        dpg.add_plot_axis(dpg.mvXAxis)
        with dpg.plot_axis(dpg.mvYAxis):
            

            for _ in range(1):
                x = [random.random() for _ in range(10)]
                y = [random.random() for _ in range(10)]
                dpg.add_scatter_series(x,y)
                dpg.bind_item_theme(dpg.last_item(), plot_theme)
                dpg.add_line_series(x,y)
                

dpg.create_viewport(width=600, height=500)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

And this is what I got:
image

@tonyzhangnxp tonyzhangnxp added the state: pending not addressed yet label Sep 29, 2024
@v-ein
Copy link
Contributor

v-ein commented Sep 29, 2024

The API add_theme_color supports color dict as input

Hmm... why do you think it does?

Also, FWIW, color_dict in your code is a list, not a dict.

If you want to draw every marker with a different color, you can render them individually with draw_circle. Maybe there are other ways, it was just first to come to my mind.

@tonyzhangnxp
Copy link
Author

Hello @v-ein

Thank you for your quick reply.
You are right, color_dict is a list.

I was greatly concerned that the UI would be stuck when using draw_circle to draw a large number of arrays.

BR
Tony

@v-ein
Copy link
Contributor

v-ein commented Sep 30, 2024

How large is large? How many colors are you going to use, and how many markers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: pending not addressed yet
Projects
None yet
Development

No branches or pull requests

2 participants