as I understand your question, when you are at freq = 20Hz, you want to be at pixel 0, and when freq = 22050Hz you want to be at pixel nPixels so that you're using the full amount of space available for the problem at hand. To do this, you need to scale the logarithm of your frequencies to the appropriate size. We do this with a constant scaling multiple in front of the log function. In order to put the origin of the x axis in the right place, we also have to add a constant term. This would look like a linear function $mx + b$, except the $x$ in this case is a log function of frequency, so $m\log(f) + b$. I am going to shorten this using logarithmic identities to $m\log(af)$ for some constant $a$.
For your particular problem, we would want to be at pixel 0 for $f=20$, and the only way to get 0 is to make sure the inside of the logarithm is equal to 1. so in this case, $a=1/20$. For $f=22050$ we want to be at pixel $nP$, so
nP = m\log(22050/20)
So $m=nP/\log(22050/20)$, which is approximately $nP/3$. Thus, given a frequency $f$, it should be located at about $p = (nP/3)\log(f/20)$.
Hopefully that lines up with the answer you've found empirically