Cosmological observations are used to test for imprints of an ultralight axionlike field (ULA), with a range of potentials V (ϕ )∝[1 -cos (ϕ /f )]n set by the axion-field value ϕ and decay constant f . Scalar field dynamics dictate that the field is initially frozen and then begins to oscillate around its minimum when the Hubble parameter drops below some critical value. For n =1 , once dynamical, the axion energy density dilutes as matter; for n =2 it dilutes as radiation and for n =3 it dilutes faster than radiation. Both the homogeneous evolution of the ULA and the dynamics of its linear perturbations are included, using an effective fluid approximation generalized from the usual n =1 case. ULA models are parametrized by the redshift zc when the field becomes dynamical, the fractional energy density fzc≡Ωa(zc)/Ωtot(zc) in the axion field at zc, and the effective sound speed cs2. Using Planck, BAO and JLA data, constraints on fzcare obtained. ULAs are degenerate with dark energy for all three potentials if 1 +zc≲10 . When 3 ×104≳1 +zc≳10 , fz c is constrained to be ≲0.004 for n =1 and fzc≲0.02 for the other two potentials. The constraints then relax with increasing zc. These results have implications for ULAs as a resolution to cosmological tensions, such as discrepant measurements of the Hubble constant, or the EDGES measurement of the global 21 cm signal.