Unfortunately there’s nothing like Matplotlib built-in, but Godot is built around vector math (videogames) so it’s definitely possible but your equations have to be lower level and somewhat more complicated.
There is function specifically to draw custom 2D vectors called _draw() which might be what you’re looking for. Have a look at this tutorial for details on how to utilise it:
There is also Line2D, which is a Node specifically for drawing polyline, maybe that’s all you need for your project?
You should feel free to adapt their code or ideas.
Thanks for your response. I have already gone through this.
My problem is to draw a line graph on a rectangular sprite based on a button click.
How do I approach this ?
Thanks in advance.
subhnand | 2021-07-12 11:43
The only complicated bit about that is actually drawing the graph.
I don’t really know how to do exactly what you want, you’ll have to code that yourself.
Use a signal from the button to make a UI panel (containing your graph) visible and also have it update (or update beforehand) the Vector2 array (PoolVector2Array) — which contains points for your line graph.
Have a script attached to the UI panel which imports the Vector2 array and uses the _draw() function to draw_multiline(...) with your updated Vector2 array (see here about draw multi-line usage).
I know you’re probably looking for some easier information to follow but drawing Vectors with code not something that can be simplified much. To get started, make a Panel or Sprite, attach a script to it and try out this code: