# Logarithmic scale problem (1 Viewer)

### Users Who Are Viewing This Thread (Users: 0, Guests: 1)

#### lgarcia12

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!!

S

#### SGT

##### Guest
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.

#### lgarcia12

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;

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 occured
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

);

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?

#### lgarcia12

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

S

#### SGT

##### Guest
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.

#### matejhowell

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

S

#### SGT

##### Guest
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

• 42.8 KB Views: 169

### The Physics Forums Way

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving