DearPyGui icon indicating copy to clipboard operation
DearPyGui copied to clipboard

Polar plots

Open ferreteleco opened this issue 4 years ago • 7 comments

I'm currently using DPG for some side projects and I would love to have the posibility to add polar plots to my GUIs (since I work a lot with angles an positioning relative to angle / distance pairs).

It will be pitch perfect either with a modification of the current plot widget or by implementing a brand new one capable of working with polar coordinates.

Thank you in advance!!

ferreteleco avatar Oct 25 '21 14:10 ferreteleco

+1 I saw a really nice polar plot here. @hoffstadt, do you know where is this plot from or how to reproduce it?

jmoraispk avatar Jun 28 '22 23:06 jmoraispk

I also would like to know if there is a good way to draw polar plots. Are there any updates on this issue?

jackthomas818 avatar Jul 28 '22 18:07 jackthomas818

In case anyone comes across this, I was able to draw polar plots using the Drawing API. I just converted my polar coordinates into cartesian coordinates and drew the polar plots using draw_polyline.

jackthomas818 avatar Aug 12 '22 18:08 jackthomas818

@jackthomas818 Thanks for updating! Do you have any repo using that code? I would like to see how it turned out.

jmoraispk avatar Aug 13 '22 23:08 jmoraispk

@jmoraispk

Unfortunately I cannot share the repository due to being proprietary code, but I can share a polar plot that was generated. Screenshot from 2022-08-15 11-05-26

jackthomas818 avatar Aug 15 '22 18:08 jackthomas818

@jackthomas818

Thanks!! That's quite a good polar plot! For sensor patterns, like antennas or microphones, this is great!

Could you perhaps post just the plot part here as a code block in case someone else bumps into this in the future?

jmoraispk avatar Aug 19 '22 20:08 jmoraispk

@jmoraispk Here is some code that draws a simple circle in a polar plot.

from dearpygui.dearpygui import *
import numpy as np

create_context()

with window(label="Polar Plot"):

    with drawlist(width=1000, height=1000):

        # size of polar drawing
        circle_radius = 400

        # drawing a simple circle
        r = 100
        theta = np.deg2rad([i for i in range(0, 360, 1)])

        # converting polar coordinates to cartesian
        points_x = r * np.cos(theta)
        points_y = r * np.sin(theta)

        points = [list(point) for point in list(zip(points_x, points_y))]

        with draw_node(tag="polar_graph_main"):
            draw_circle(
                [0, 0],
                circle_radius,
                color=[0, 255, 0],
                fill=[31, 51, 61],
            )
            # polar grid circles, can be any number
            ncircles = 8
            with draw_node():
                draw_polyline(points, color=[255, 0, 0])
                for i in range(0, ncircles):
                    draw_circle(
                        [0, 0],
                        circle_radius / ncircles * (i + 1),
                        color=[74, 74, 74],
                    )
                # polar grid lines
                draw_line(
                    [0, -circle_radius],
                    [0, circle_radius],
                    color=[74, 74, 74],
                )
                draw_line(
                    [-circle_radius, 0],
                    [circle_radius, 0],
                    color=[74, 74, 74],
                )

                draw_line(
                    [
                        -circle_radius * np.cos(np.deg2rad(45)),
                        circle_radius * np.sin(np.deg2rad(45)),
                    ],
                    [
                        circle_radius * np.cos(np.deg2rad(45)),
                        -circle_radius * np.sin(np.deg2rad(45)),
                    ],
                    color=[74, 74, 74],
                )
                draw_line(
                    [
                        -circle_radius * np.cos(np.deg2rad(135)),
                        circle_radius * np.sin(np.deg2rad(135)),
                    ],
                    [
                        circle_radius * np.cos(np.deg2rad(135)),
                        -circle_radius * np.sin(np.deg2rad(135)),
                    ],
                    color=[74, 74, 74],
                )

    # this moves the graph so that it is entirely visible in the viewport
    apply_transform(
        f"polar_graph_main",
        create_translation_matrix([circle_radius + 50, circle_radius + 50]),
    )
create_viewport(title="Custom Title", width=1920, height=1080)
setup_dearpygui()
show_viewport()
start_dearpygui()
destroy_context()

jackthomas818 avatar Aug 22 '22 18:08 jackthomas818

Polar plots are not on the roadmap for DPG 1.

bandit-masked avatar Jan 05 '23 22:01 bandit-masked