Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Proportional Scaling of XY Plot in Excel

Status
Not open for further replies.

Spurs

Mechanical
Nov 7, 2002
297
An XY Plot in Excel can be easily created. The problem I have encountered is that I cannot force Excel to maintain a 1:1 aspect ratio between the x and y axis on the chart under the following conditions

1)the input data can vary

and

2) the monitor where the chart is viewed can have different pixel proportions which will disrupt the aspect ratio

Any suggestions?

Is there a macro that can fix this?

 
Replies continue below

Recommended for you

1) is fixable, in a very ugly way, by generating a 'phantom' second series that contains the max and min of the actual graph data, and then switching off both lines and markers for the phantom series and deleting its legend.

This will force the x and y axes to have the same limits.

Cheers

Greg Locock
 
Greg

This still doesnt solve the problem of the effect monitor pixel proportions on the aspect ratio.

Any suggestions for that?
 
This is what code would look like to set the horizontal and vertical dimensions the same:

ActiveChart.PlotArea.Select
Selection.Width = 400
Selection.Height = 400


You then need to figure out the pixel dimensions of the display and scale accordingly

TTFN
 
IRstuff

I have tried that in the past. The problem still is in the proportioning to the actual display somehow.

Thanks for your help.
 
With functions below you can obtain the screen resolution and use it for correction of the graph.

Declare Function GetSystemMetrics32 Lib "User32" _
Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long

Function display_X()
display_X = GetSystemMetrics32(0)
End Function

Function display_Y()
display_X = GetSystemMetrics32(1)
End Function

Mirekp
Mechanical calculations
 
Thanks all - I will give these things a try
 
Spurs,
You can set XY scales proportionally without macros, but using additional chart series consisting just of two data points to plot a diagonal line with equal tangents. The tangent length shall be dx=max(x)-min(x) or dy=max(y)-min(y) whichever is larger. Based on tangent length Excel will automatically set equal (or almost equal) limits to X and Y axes.

Step 1: Plot area shall be square (you can do it manually or in VBA (see IRstuff postage)
ActiveChart.PlotArea.Select
Selection.Width = 400
Selection.Height = 400

Step 2: Reserve 2x2 range for new series. Using IF function enter formulas for xo and yo

if dx >= dy
xo(1)=min(x) yo(1)=(max(y)+min(y)-dx)/2
xo(2)=max(x) yo(2)=(max(y)+min(y)+dx)/2

if dx < dy
xo(1)=(max(x)+min(x)-dy)/2 yo(1)=min(y)
xo(2)=(max(x)+min(x)+dy)/2 yo(2)=max(y)

Step 3: Add new series to the chart. Set line and marker width to none to make chart invisible.

On my website I have a file implementing this technique:
Hope I was clear!
 
Yakpol,
Very interesting Webpage. Nice to see the sharing of information. Keep up the good work!
 
i dont know if this will work but....

could you simply add two cells to the spreadsheet and have the user type in his screen resoultion, then scale the plot using that info?

daveleo

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor