-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
two y axis with different coordinates, one on left and one on right #20
Comments
Hi, I think this is not possible. You can create a second Y axis but you can not attach it to a specific plot. |
Hi, Lionel, thanks for your response. I know it is complex to add such feature, so I think leave this issue open. Maybe some day we can find a way to implement it. Thanks. |
Some good news about two Y axies in Wisteria-Dataviz (also a wxWidgets based project), see here: Any feature about two Y axies in the chart? · Issue #43 · Blake-Madden/Wisteria-Dataviz |
I have one question, for the code here: wxMathPlot/mathplot/mathplot.cpp Lines 1757 to 1859 in 93a3405
If I have a second Y(in the right margin) axis, and if I set the maxY value and minY value for this Y axis, and can I calculate each ticks and each labels for this second Y axis? For example, I have the first Y axis on the window, which is in the Y coordinate range [0, 100], and for the second Y axis, it ranges at [0, 200]. So, for each ticks label in the right axis is twice as the each ticks in the left axis. I mean, is it possible to customize the tick labels in the right Y axis? I think the above is the first step. If I can correctly draw the second Y axis, than, I will find a way to draw the lines according to the "scale and shift" of the second Y axis, because I can easily apply the transforms on the lines (x,y) coordinates. |
Hi, For your example, on can simply introduce a new property factor in the mpScaleY class. Then in line 1838 you will have : But well, I don't think that's what you want. |
see here for discussion: two y axis with different coordinates, one on left and one on right · Issue GitHubLionel#20 · GitHubLionel/wxMathPlot — GitHubLionel#20
I have commit my first changes to my fork (* try to implement a second Y axis which has different tick labels) here is the result: It looks good.
This is one issue, yes, I see the a curve is not based on an axis, but I think I may need to extend a new curve class, which can depends on the "mpScaleY2". My design strategy is that I can have a function 1, I have already know how to draw the Y axis and Y axis's tick lines(horizontal lines) The hardest part is the step 2. Here comes another issue, does the "tick lines" draw twice if I have both Y axis one the left side, and Y2 axis one the right side? How can I determine both the left Y and right Y are drawing in the same "steps" (in pixel coordinates). |
Hi, The crux of the problem is the definition of m_scaleY. All other parameters are defined with it, like m_posY.
You have sources in the sandbox repository : https://github.com/GitHubLionel/wxMathPlot/tree/master/Sandbox There are some problems when you resize the windows or when you select an area, but for the moment, it is just a test. |
We have strange behaviour when we select an area to zoom. Since the coordinates are in the first axis referential, if we select an object in the second axis referential, the result is correct but not what we expected. I don't know how to correct this effect. |
Hi, thanks for your effort, I would suggest that you could use a new "git branch" to handle such feature implementation, because if I try to use the new file inside the "SandBox" folder, it is hard to check the modifications. I haven't tried your code in the "SandBox" yet, I will test them soon. About the issue you mentioned:
I think it is OK to keep a scale and shift value from the coordinates transform based on Y1 axis to Y2 axis. That scale and shift value should be fixed. So, once you zoom the Y1 axis, you should also zoom the Y2 axis in the same level. I mentioned this way in my previous comments. Thanks. |
Sorry for the late reply. I just copy the wxMathPlot.h/cpp file from the SandBox folder to the "mathplot", and can you show me what is the client code to use the second Y axis? Thanks. |
Has I write previously,
|
Thanks. I see you mentioned issue. This issue happens you use the mouse to drag a rectangle, and you want to zoom to this rectangle. So, my guess is that the issue happens from the function:
Here, the So, later, inside the function
I'm debugging the above function, and try to see if I can solve the issue. |
see here for discussion: two y axis with different coordinates, one on left and one on right · Issue GitHubLionel#20 · GitHubLionel/wxMathPlot — GitHubLionel#20
I have my test code in this commit: add a second Y axis testing code I see that sometimes, the relative position/scale of the two curves depends on Y1 and Y2 axes are changing. From my point of view, they should be fixed. One issue I see is the "tick line" will becomes interleaved, see below images: When I use the mouse scroll to zoom in, it becomes like below: |
Suppose curve1 is depends on Y1, and Y1 has the property: So, to draw curve1 on the screen(pixel coordinates), I have to: For curve2 on Y2 axis, when draw on the screen, you have to But when you zoom the screen, you have to adjust the Currently, I see the relative position and scale are not fixed. |
… and Y2 axes see discussion here: GitHubLionel#20
OK, I think the below commit can fix such problem, see here: * we should key the relative position and scale of the curves from Y1 and Y2 axes |
When I try to use the right mouse context menu, and click the "lock aspect" item, I see it still has some zoom issue. |
Ok, I add your correction and add a test. Now it is working when we zoom an area, fit or resize. It is working also with lock aspect but have again a problem when we unlock aspect. But with a fit, thinks return good. |
I think one issue remains: how to initialized the initial fit. I mean for example, we have curve0 and curve1 on Y1, and curve2 and curve 3 and Y2. Now, I think the correct way to make a fit is: Find the bounding box of "curve0 and curve1", and find the bounding box of "curve2 and curve3". Then, we need to find an initial If I remember correctly, when start the program, only the "curve0 and curve1" will fit to the canvas window. In the future, maybe, we can make |
Yes need more reflections ! |
Thanks.
What does this sentence mean? I looked at your code, and I see you have a bool variable I'm not sure what does this variable used for, it looks like in the function:
And
In the above two cases, the code goes to the first branch. In other cases, it goes to the else branch.
I'm not understand this logic. Thanks. |
In last post, I try another approach by computing bound for Y and Y2. |
You "last post" means the last commit you pushed minutes ago? |
Yes |
I think the English translation is the "series", so you have "series 0", "series 1" for different curves. |
Yes, I know this. If I remember correctly, I have report such issue before.
Sorry, I do not understand your sentence above.
Good, I see you merged all the changes in sandbox to the main folder. |
LIMIT increase a little the bound. |
In the function: I have to use this else condition:
Because I have some |
I think I have found a bug of the fit function
When started, I see the plot looks like below: When I use the mouse to zoom to a rectangle, I got the correct result: This is the latest git head code of the demo project. |
This is not a bug. Result is correct, this the effect of LIMIT now renamed m_limit_percent.
|
OK, thanks for the help. I remembered that I have reported such issue before, see here: bugs in calculation the bounding box · Issue #18 · GitHubLionel/wxMathPlot I think we should consider the actual x or y's range, not the values. For example, if the x coordinates range is [40000, 40020], it should be the same as the [0, 20], because they have the same range. But what I reported in that issue is that currently, the gap is depends on the values, not on the ranges length. So, for the current code:
This is NOT correct, it depends on the values, not one the range length. It should be like below:
|
I read the code how to calculate the boundary of the x or y. I see the logic is that, when you add each point, you need to calculate the bounding box. When calculate the bounding box's x limit(the minimal x or maximal x), you use the m_limit_percent. I think this logic is not correct. When calculating the bounding box, we should NOT use the m_limit_percent, as you mentioned, you should make m_limit_percent == 0. So, you got an accurate bounding box. But when you run the fit function, you have to expand the bounding box a little. So, for a line which has range [40000, 40020], you may has an actual range I hope you can understand my idea. Thanks. |
Ok, I try to explain why I use this method. |
If I understand your idea, this is some kind of Kalman filter, but you still need a delta, not the absolute valve of the point. I think my idea does not conflict with your idea, The delta is just a range. So you need to keep some space in the margin, In this case when new point added you don't need to repaint the whole plot chat, You just need to draw the new point. |
Ok, I try a new approach with delta on X and Y. |
I see your new approach, but I still don't know the logic. If I have several points like:
In this case, the y delta could be "0"? Is that correct? |
I have such test code for the demo project:
and
You see, by default, all the 3 lines were added to the Y axis, and there is NO lines in the Y2 axis. When start up, it looks like below: This looks OK. Now, in the configure dialog, I try to select the "serial 1" to the Y2 axis, see the below image: After "Fit" the screen, the result looks wrong here, see the image below: You can see the arrow in the above image, it should span the whole Y2 ranges. |
Ok, I add a test on UpdateBBox. |
I draw an image of how the bounding box can be calculated. We should calculate the actual bounding box(the red dashed rectangle), and the outer blue rectangle is the window/chart size. There is a gap, such as 10% between those two rectangles in up/down/left/right 4 direction. So, for the left(minimal X) direction:
Here, we could still use the I hope you can understand my idea. When adding one data point, the |
How to draw a customized class object in the Y2 axis related coordinates. Hi, I have a customized class like below:
This object draws like X axis, and has a m_Y field, so I can draw a horizontal line. But what I want is that I would like to draw this horizontal line in the Y2's coordinates system. I see that if I want to draw on a Y2's coordinates, I have to derive this class from the |
Yes because we have the choice between fixed or automatic bound. I need to update the code for Y2. If we want extra marge, the more simple is to add this marge when we draw the box around the curve. For example, if we want 5 pixels, then in mpWindow::OnPaint method :
For an horizontal line, why not use mpFX :
Then to add layer horizontal line : |
Hi, about the HorizontalLine class design, thanks. It's working now, here is the code that I derived from mpFX
Those lines are like threshold lines. Also, I have disable the bounding box calculation:
And the type I set is: |
Ok, I see what you want. Simply is to use mpFunction. |
Thanks, the new class works OK, See the image below, it is shown in the Y2 coordinates. And here is the related code:
One minor question: is it possible to draw this horizontal line in the background as the "axis" does. I mean when drawing all the layer objects, those horizontal lines should be drawn before the curves. |
Simply add horizontal line layer before series layer. |
Ok, I add z-order for plot layer. Not sure of order but we must not break the original order plot.
|
Thanks, it works OK now. Another minor issue: The circle and square are using the same size = 6, but they look different.
It looks like the circle has radius = 6, but for square, the side = 6. |
Yes it is correct. |
OK, I think I'm going to close this issue, because all the feature I requested is completed. Thanks. If I have other questions or issues, I think will create new issues. |
see here for discussion: two y axis with different coordinates, one on left and one on right · Issue GitHubLionel#20 · GitHubLionel/wxMathPlot — GitHubLionel#20
…ialog See discussion here: GitHubLionel#20 (comment)
Hi, I have a feature request which I would like to ask here.
In my application, I need to plot two plots in a same graph/chart. But each plot has its own unit.
This means that I need two Y axis, one on left margin and one on right margin.
Is this possible? I'm not sure you can understand my need, maybe, this is something like in the below link:
Plots with different scales — Matplotlib 3.8.3 documentation
Thanks.
The text was updated successfully, but these errors were encountered: