在 ListLogLogPlot 的刻度标签中强制使用科学计数法
我正在尝试在 ListLogLogPlot 上自定义格式的刻度标签。通过搜索 Mathgroup 档案,看起来混乱刻度标签的常用方法是使用 AbsoluteOptions
提取它们,使用自定义格式运行替换规则,然后使用以下命令显式地将它们提供给绘图函数: Ticks->{...}
选项。但是,以下内容不适用于 ListLogLogPlot:
foo = ListLogLogPlot[Range[20]^3, Frame -> True];
ticks=(FrameTicks /. AbsoluteOptions[foo, FrameTicks])
有关如何处理此问题的任何想法?..
编辑:这里有很多好的答案!接受巫师先生的方法,因为它被证明是解决当前问题的最简洁的方法,但我认为自己将来会使用建议的其他方法。
I am trying to custom-format tick labels on a ListLogLogPlot. By searching Mathgroup archives, it looks like the usual way to mess with tick labels is to extract them using AbsoluteOptions
, run a replacement rule with the custom format, and then explicitly feed them to the plotting function with the Ticks->{...}
option. However, the following doesn't work for ListLogLogPlot:
foo = ListLogLogPlot[Range[20]^3, Frame -> True];
ticks=(FrameTicks /. AbsoluteOptions[foo, FrameTicks])
Any ideas on how to deal with this?..
Edit: lots of good answers here! Accepting Mr. Wizard's since it proved to be the most concise way to solve the immediate problem at hand, but I see myself using the other methods suggested in the future.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
人们可以使用替换来直接弄乱标签,绕过
Option
/AbsoluteOptions
:感谢Alexey Popkov,现在它已经得到了改进并且不再那么脆弱。
One can use replacements to mess with the labels directly, bypassing
Option
/AbsoluteOptions
:Thanks to Alexey Popkov this is now improved and less fragile.
和 Sjoerd 一样,我通常更喜欢编写一个动态计算刻度的函数:
Like Sjoerd, I generally prefer to write a function that computes the ticks on the fly:
为了补充 Brett 的答案,请查看LevelScheme 中的
CustomTicks
包。它提供了两个用于生成刻度线“LinTicks和
LogTicks”的函数,每个函数都有许多格式选项。目前,它要求您自己执行对数,即给出
的列表数据,显然你必须将
Log[Base, data]
与ListPlot
一起使用,但它是可行的。我已向 Mark Caprio 提交了一个补丁,以便以下内容将执行与上面完全相同的操作如果补丁被接受,则可以通过设置选项
PlotType
来访问旧形式的LogTicks
code> 为Linear
,默认为Logarithmic
。使用CustomTicks
的优点是其他基础很容易,它会自动按照您想要的格式设置格式。
编辑:我还想指出,
CustomTicks
本身是可加载的,与LevelScheme
的其余部分分开。而且,由于它是一个小包,因此没有那么多额外的开销。To complement Brett's answer, look at the
CustomTicks
package in LevelScheme. It provides two functions for generating tick marks 'LinTicksand
LogTicks`, and each has a host of formatting options. Currently, it requires you to perform the logarithm yourself, i.e.gives
For a list of data, obviously you'd have to use
Log[Base, data]
withListPlot
, but it is workable. I have submitted a patch to Mark Caprio so that the following would do the exact same thing as aboveIf the patch is accepted the old form of
LogTicks
would be accessible by setting the optionPlotType
toLinear
,Logarithmic
is default. The advantage of usingCustomTicks
is that other bases are easyand it automatically formats it like you want.
Edit: I'd also like to point out, that
CustomTicks
is loadable by itself, separate from the rest ofLevelScheme
. And, as it is a small package, there isn't all that much additional overhead.对我来说看起来像一个错误。简单调用
AbsoluteOptions[foo]
会产生错误消息。不过,普通的旧Options[foo]
工作正常。Looks like a bug to me. Simple calling
AbsoluteOptions[foo]
yields error messages. Plain oldOptions[foo]
works fine, though.将包含此代码的电子邮件发送至[电子邮件受保护]。他们将能够告诉您是否有已知的更好的解决方法。
Send an email with this code in it to [email protected]. They will be able to tell you if there's a known better workaround.