Home > Back-end >  No module named 'basic_units'
No module named 'basic_units'

Time:10-31

I'm trying to run the code below, but I keep getting the same error : "ModuleNotFoundError: No module named 'basic_units'".

import sympy as sym
import math
import numpy as np
import os
import matplotlib.pyplot as plt
from basic_units import radians

fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
ax.plot([np.pi, np.pi], [0, 10], xunits=radians)

plt.show()

I've seen that used in other code, but I just can't get it to work.

I was trying to make a polar plot with the angles in radians, and this seemed to be the only solution I could find, so I tried to run this test, but I encountered this error

CodePudding user response:

basic_units is not a python package, you should have a look for official matplotlib document:

Radian ticks#

Plot with radians from the basic_units mockup example package.

This example shows how the unit class can determine the tick locating, formatting and axis labeling.

This example requires basic_units.py

import matplotlib.pyplot as plt
import numpy as np

from basic_units import radians, degrees, cos

You could download above source code & put in your project.

CodePudding user response:

Did you download basic_units.py file as numpy documentation mentions (https://matplotlib.org/stable/gallery/units/radian_demo.html)? If yes, you have to provide a valid path in the import statement. Now you're trying to import it as a module, but it should be a file. Like:

from .basic_units import radians

or

from my_code.src.basic_units import radians
  • Related