A magnitude 5.1 earthquake shook areas northwest of Los Angeles, including several aftershocks over 3.0.