So I made a custom module that uses matplotlib and when I try to use that module, it doesn’t show. When I put the code in the same code as the module then it runs, how do I fix this?
def init():
global x
x = 12
def update():
global x
x = 12
def draw():
print("draw")
plg.set_map()
plg.start(init, update, draw)```
I'm using pydroid on android if that matter
I noticed that you have imported these two modules without actually using them in your script:
import numpy as np
from matplotlib.patches import Rectangle, Circle, Polygon
If you will not be using them, then there is no reason to have them clutter your script.
Based on your script, what you really want is this:
import matplotlib.pyplot as plt
This allows you to create this (among other use cases in your script):
fig, ax = plt.subplots()
Another discrepancy is that you have x defined as a global variable within two functions yet it is not being used outside of them. When you define a variable as global within functions it implies that they are being used / modified in the global namespace (outside the functions).
You should also define the functions init, update, and draw before the start function.
Plt thing is I just copied so badly so the import matplotlib.pyplot as plt
And the plt.show being part of the loop doesn’t help. The thing is when I run the code it just outputs draw and map, but doesn’t show the graph, so Im guessing it’s showing the wrong window or smth, cause the code works if I put it in the same code as the module