In this letter, we investigate the ionospheric variations associated with the Yaan earthquake that occurred on April 20, 2013 in China by using the total electron content (TEC) derived from ground-based Global Positioning System observations and a global ionosphere map (GIM). Geomagnetic and solar activities are taken into account. First, we focus on the coseismic ionospheric disturbances of the earthquake. The time period of the variations is about 15 min after the seismic rupture, and the maximum amplitude is about 0.1 TEC units. We then examine the preseismic ionospheric anomalies by the TEC values from the GIM and the electron density $(Ne)$ values reconstructed by computerized ionospheric tomography. Temporal variations show that the TEC and $Ne$ values simultaneously increased on April 5–8, 2013, which are 12–15 days before. This increase is possibly related to the earthquake. Spatial analysis shows that anomalies tend to appear around the epicenter and their conjugate points.