Logarithmic Scale: Calculating Evenly Spaced X Values

Click For Summary
SUMMARY

This discussion focuses on generating evenly spaced X coordinates for plots using a logarithmic scale on the X-axis. The solution involves calculating logarithmic values for specified starting and ending points, then generating evenly spaced points using the formula: log_x(n) = (n(log_end - log_start) / Count) + log_start. The final X coordinates are derived by exponentiating these logarithmic values: x(n) = pow(10, log_x(n)). This method effectively allows for the specification of arbitrary ranges and point counts on a logarithmic scale.

PREREQUISITES
  • Understanding of logarithmic functions and their properties
  • Familiarity with the concept of exponential functions
  • Basic programming skills for implementing mathematical formulas
  • Knowledge of plotting libraries or tools for visualizing data
NEXT STEPS
  • Implement the logarithmic spacing formula in a programming language of choice
  • Explore plotting libraries such as Matplotlib (Python) or D3.js (JavaScript) for visual representation
  • Learn about logarithmic scales in data visualization and their applications
  • Investigate advanced plotting techniques for handling arbitrary ranges and scales
USEFUL FOR

Data scientists, software developers, and anyone involved in data visualization who needs to create plots with logarithmic scales and evenly spaced X coordinates.

Jdo300
Messages
548
Reaction score
5
Hello All,

I am working on a program that produces plots that use a logarithmic scale on the X-Axis (for showing decade frequency ranges). The Y-axis can have any arbitrary value and I'm not thinking about that at this point, but here is my question.

Say, for simplicity that every Y-value on the graph was set to a value of 10 so that a straight line is always drawn. Is there a way to determine the X coordinates such that they appear to be evenly spaced going from left to right on the graph even though the X-axis is displaying a logarithmic scale? I want to know this so that I can generate a plot that has x number of evenly spaced points. The second challenge is I want to be able to specify a starting and ending point on the X-axis to draw the graph (it may not always start at 0). How would I design a formula that if I enter the starting X value, end X-value, and number of points, that i could spit out point n in the range to plot a function with?

Thanks,
Jason O
 
Physics news on Phys.org
I think so.

Say you're doing the logarithms to the base of 10. Then to get evenly spaced x-coordinates when the x-axis is on a log scale, just start with a number (1, for instance) and multiply by 10 over and over again. So

x = 1, 10, 100, ..., 10^n

Taking the Log gives you:

Log x = 0, 1, 2, ..., n

Which, I believe, is exactly what you wanted.


Say you wanted them spaced at intervals of 2 rather than 1. Then multiply by 100 each time. Say you wanted 1/2. Then try sqrt(10). Etc.
 
So Far here is what I have come up with so far, only this function works for a linear scale and not logarithmic:

x(n) = (n(End - Start) / Count) + Start

where:

n = position in the array of points
End = Ending X coordinate
Start = Starting X coordinate
Count = Number of points in the array

I basically want to figure out how to convert this function to the other scale.

- Jason O
 
Hi AUMathTutor,

That sounds like the right idea. But I'm not sure how to implement it when you have arbitrary starting and ending points along with n number of points specified.

Thanks,
Jason O
 
Alright, so you want "count" many evenly-spaced points between "start" and "end".

First, get the log base 10 of start. Call it log_start. Then get the log base 10 of end. Call it log_end.

Next, generate evenly spaced points using the same method you posted above, but call the array log_x(n). So we have...

log_x(n) = (n(log_end - log_start) / Count) + log_start

Then, just go through the array and set

x(n) = pow(10, log_x(n))
 
For instance, let start=10, end=10,000, and count=4. Then...

log_start = 1
log_end = 4

log_x(0) = log_start
log_x(1) = (log_end - log_start)(1/4) + log_start = (1/4)log_end + (3/4)log_start
log_x(2) = (log_end - log_start)(2/4) + log_start = (1/2)log_end + (1/2)log_start
log_x(3) = (log_end - log_start)(3/4) + log_start = (3/4)log_end + (1/4)log_start
log_x(4) = (log_end - log_start) + log_start = log_end

so...

x(0) = start = 10
x(1) = (end)^(1/4) + (start)^(3/4) = 15.623413251903490803949510397765
x(2) = (end)^(1/2) + (start)^(1/2) = 103.16227766016837933199889354443
x(3) = (end)^(3/4) + (start)^(1/4) = 1,001.7782794100389228012254211952
x(4) = end = 10,000

There you have it. You'll have to iron out issues related to whether you want count or count+1 points, but still. The idea is there.
 
Thank you very much! I'll try this out and let you know what I end up with :smile:.
 
Hi AUMathTutor,

I finally had a chance to test out the formula you gave me. It works like a charm! Thanks!

- Jason O
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
15K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 4 ·
Replies
4
Views
39K