The mass changed by injecting molecules at the left. The density (mass/volume) changes with the injection of the mass. This would be a very difficult experiment to perform in reality, because both the pressure and volume must be held constant.