vba 使 Excel 图表上的 X 轴和 Y 轴刻度相等
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1723059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Make the X and Y axis scales equal on an Excel chart
提问by Jean-Fran?ois Corbett
I'd like the X and Y axes of my Excel charts to have the same scale on the screen, because I'm plotting geographical data. A 1km by 1km square should look like a square, not like a rectangle, i.e. no squishing of the map in one or the other direction. In Matlab, the command that would do this is axis equal.
我希望 Excel 图表的 X 轴和 Y 轴在屏幕上具有相同的比例,因为我正在绘制地理数据。一个 1km x 1km 的正方形应该看起来像一个正方形,而不是一个矩形,即在一个或另一个方向上没有压扁地图。在 Matlab 中,执行此操作的命令是axis equal.
How do I do this using VBA?
我如何使用 VBA 做到这一点?
Am I overlooking an even simpler solution directly in Excel?
我是否直接在 Excel 中忽略了一个更简单的解决方案?
回答by Stewbob
In addition to guitarthrower's answer you will need to do the following: Select the 'Plot Area' of the chart and then manually set the height and width of the plot area.
除了吉他手的回答,您还需要执行以下操作:选择图表的“绘图区域”,然后手动设置绘图区域的高度和宽度。
Sheets("Chart1").PlotArea.Select
Selection.Height = 500
Selection.Width = 500
Just setting the axis min and max values will still allow the chart to be 'squished'.
仅设置轴的最小值和最大值仍将允许图表被“压扁”。
回答by Brandon
When you select the plot area and write Selection.Width = something, the Width value you are setting also includes the width of the axis labels/text. This may not be what you want.
当您选择绘图区域并写入时Selection.Width = something,您设置的 Width 值还包括轴标签/文本的宽度。这可能不是您想要的。
Instead, you can set the INSIDE Width/Height value using
相反,您可以使用设置 INSIDE Width/Height 值
Selection.InsideHeight = 250
Selection.InsideWidth = 250
回答by George
Another method similar to Stewbob's is to set the limits to some ratio of each other (my plots are 4 times as wide as they are tall) and then use the height to set the width.
另一种类似于 Stewbob 的方法是将限制设置为彼此的某个比例(我的图的宽度是高度的 4 倍),然后使用高度来设置宽度。
ActiveChart.PlotArea.Select
Selection.Width = Selection.Height * 4

