What is the issue with log scales and plotting values less than 1?

Click For Summary

Discussion Overview

The discussion revolves around the challenges of implementing a logarithmic scale in a plotting application, specifically when handling values less than 1. Participants are exploring the behavior of mouse click events on a logarithmic plot and the resulting discrepancies in marker placement compared to a linear scale.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related
  • Mathematical reasoning

Main Points Raised

  • One participant describes an issue where markers are placed incorrectly on a logarithmic scale when clicking on values less than 10, resulting in a shift to the right.
  • Another participant notes that the logarithm of numbers between 0 and 1 is negative, which complicates the placement of markers at those values.
  • A participant shares Java code related to mouse click events and how it translates screen coordinates to plot coordinates, seeking advice on correcting the marker placement.
  • Some participants suggest that there is a non-logarithmic function governing the relationship between clicked points and the resulting values, indicating a potential misunderstanding of the logarithmic scale.
  • One participant proposes that adjusting the origin of the plot to values greater than 0 could help address the issue of plotting values less than 1.

Areas of Agreement / Disagreement

Participants express differing views on how to handle values less than 1 in logarithmic plots, with no consensus on a definitive solution. Some agree on the challenges posed by logarithmic scales, while others propose various approaches to mitigate the issue.

Contextual Notes

There are unresolved mathematical steps regarding the transformation of coordinates from logarithmic to linear scales, and the discussion includes assumptions about the behavior of logarithmic functions that may not be fully explored.

lgarcia12
Messages
3
Reaction score
0
I am working on a homework for a programming class. We have to create a Logarithmic plot and add to it a marker when the program is running on the click of the mouse. That is NOT the problem :) , in fact, that's very simple!
My problem, however, is with the scale. When my plot is in linear scale it adds the marker right where it should. By that I mean that if I click on point (1,2) it adds my marker on (1,2). Now, when I switch to logarithmic scale, if I click on (0,0) it adds the marker on (1,1). If I click on values greater than 10, it adds the marker at the place where I clicked. But when my values are lower than 10, the marker is shifted to the right. How do I solve that problem? I already tried converting the values I get from my mouse-click event to logarithmic values and they are wrong. In fact I get negative numbers when the values are lower than 1; so the marker is shifted to the left. I am not good at all with log scales; so, please help me!
 
Physics news on Phys.org
lgarcia12 said:
I am working on a homework for a programming class. We have to create a Logarithmic plot and add to it a marker when the program is running on the click of the mouse. That is NOT the problem :) , in fact, that's very simple!
My problem, however, is with the scale. When my plot is in linear scale it adds the marker right where it should. By that I mean that if I click on point (1,2) it adds my marker on (1,2). Now, when I switch to logarithmic scale, if I click on (0,0) it adds the marker on (1,1). If I click on values greater than 10, it adds the marker at the place where I clicked. But when my values are lower than 10, the marker is shifted to the right. How do I solve that problem? I already tried converting the values I get from my mouse-click event to logarithmic values and they are wrong. In fact I get negative numbers when the values are lower than 1; so the marker is shifted to the left. I am not good at all with log scales; so, please help me!
It's difficult to know what is happening without seeing your code. Some ideas:
The logarithm of 1 is 0, so when you click on (0,0) you are really clicking in (log 1, log 1). Anyway, you cannot have the poin (0,0) in a log scale, since log 0 = - infinity.
The logarithm of a number between 0 and 1 is negative.
 
The code is in Java. We are using a library called JFreeChart to create the chart. Here is the click event where everything happens:

Code:
public void mouseClicked (MouseEvent e)

  {

    if (SwingUtilities.isRightMouseButton (e))

      return;

    if(pointerAdded)

        return;



    //These return the x,y position on the screen or screen location
    int x = e.getX ();

    int y = e.getY ();


    // Translates a screen location to a Java2D point. 
    Point2D p = translateScreenToJava2D (new Point (x, y));


    //create Plot object
    XYPlot plot = getChart ().getXYPlot ();

    
    //get the chart renderer

    ChartRenderingInfo info = getChartRenderingInfo(); 


    //The area where the clicked occurred
    Rectangle2D dataArea = info.getPlotInfo().getDataArea(); 




    //Get the plot coordinates of where the event ocurrs
    double xx = plot.getDomainAxis ().java2DToValue (p.getX (), dataArea, plot.getDomainAxisEdge ());


    double yy = plot.getRangeAxis ().java2DToValue (p.getY (), dataArea, plot.getRangeAxisEdge ());


   
 

    //Add the custom annotation

     CircleDrawer cd = new CircleDrawer(

            Color.RED, Color.BLACK , new BasicStroke(1.0f), null);

    
 

    XYAnnotation bestBid = new XYDrawableAnnotation(

    		xx, yy, 11, 11, cd

        );

    


    this.renderer.addAnnotation(bestBid);

    pointerAdded = true;

    repaint ();

  }

As you can see, the points come out straight from the plot.
About what you say, you're right and I had noticed that before. Now, my question is, how do I go from (log 1, log 1) to my linear numbers so that I can get the right position?
 
I just did a quick test to see what the event returns. As I click closer to 0, it results in a number sifted more and more to the right. I am only showing the x coordinate since the y have exactly the same results. Also, the resulting values are approximate since I did not zoom in close enough in the plot to click exactly on the number.

Click on Result
10 10
9 9.118812375
8 8.223735874
7 7.307858871
6 6.444623616
5 5.50047321
4 4.624704838
3 3.70626008
2 2.820675981
1 1.90761842
0 1.003834079

it looks like a function, I just don't know how to find it. I think that if I find it, I can solve my problem.
Thanks
 
lgarcia12 said:
I just did a quick test to see what the event returns. As I click closer to 0, it results in a number sifted more and more to the right. I am only showing the x coordinate since the y have exactly the same results. Also, the resulting values are approximate since I did not zoom in close enough in the plot to click exactly on the number.

Click on Result
10 10
9 9.118812375
8 8.223735874
7 7.307858871
6 6.444623616
5 5.50047321
4 4.624704838
3 3.70626008
2 2.820675981
1 1.90761842
0 1.003834079

it looks like a function, I just don't know how to find it. I think that if I find it, I can solve my problem.
Thanks

This is really weird. It is not a logarithmic function. if you call Y the vector of clicked points and X the vector of results, you obtain:
y = 1.1104x - 1.1234.
 
can you post the code? I have an idea, but don't know if it defeats the purpose or not.

Would flooring the result be a work around?

Matt
 
SGT said:
This is really weird. It is not a logarithmic function. if you call Y the vector of clicked points and X the vector of results, you obtain:
y = 1.1104x - 1.1234.
The problem is with your labelling. There is no point (0,0) in a log plot. If you must plot numbers that are less then 1, you should put your origin at (o.1, 0.1) or (0.01, 0.01). Remember that the distance between 0.1 and 1 is the same as from 1 and 10. See anex graph. That is what makes the linear relationship between clicked point and result skewed.
 

Attachments

  • Logplot.jpg
    Logplot.jpg
    41.8 KB · Views: 630

Similar threads

  • · Replies 2 ·
Replies
2
Views
16K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
0
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
21
Views
5K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 4 ·
Replies
4
Views
3K