We explore the possibility that a scalar field with appropriate Lagrangian can mimic a perfect fluid with an affine barotropic equation of state. The latter can be thought of as a generic cosmological dark component evolving as an effective cosmological constant plus a generalized dark matter. As such, it can be used as a simple, phenomenological model for either dark energy or unified dark matter. Furthermore, it can approximate (up to first order in the energy density) any barotropic dark fluid with arbitrary equation of state. We find that two kinds of Lagrangian for the scalar field can reproduce the desired behaviour: a quintessence-like with a hyperbolic potential, or a purely kinetic k-essence one. We discuss the behaviour of these two classes of models from the point of view of the cosmological background, and we give some hints on their possible clustering properties.