Python and matplotlib

As you intend to run this code exclusively in Rhino 6 or 7 (and not in Rhino 8(like this) / it is straightforward to install Python 3 libraries.).
However, for a quick fix to make your code or script work in Grasshopper, you can create a Python 2 script to send data(in your case data to make a plot) to your Python 3 script and execute it within your system’s Python environment (similar to the example provided).