Onmyodo, "the way of yin and yang," is the Japanese system of divination, cosmology and ritual that grew from Chinese natural philosophy imported into Japan and there developed into something distinctively its own. Its raw materials were Chinese: the interplay of yin and yang (Japanese on and yo), the five phases or elements (gogyo, wood, fire, earth, metal, water), the sexagenary calendar, and the arts of astrology, calendar-making and geomancy. Under the ritsuryo state these were institutionalised in a government office, the Onmyoryo (Bureau of Yin and Yang), whose officials, the onmyoji, handled the calendar, observed the heavens for omens, and advised on the timing and direction of the court's actions.
From this grew an elaborate practice of avoiding misfortune: directional taboos (katatagae, changing one's route to avoid an inauspicious direction) and days of ritual seclusion (monoimi) governed the lives of the Heian aristocracy, for whom the onmyoji's reading of lucky and unlucky was a constant concern. Its most legendary practitioner, Abe no Seimei (921-1005), became a figure of folklore, credited with commanding spirit-servants (shikigami) and remembered in shrines, theatre and, today, popular fiction and film.