Mathematica 中绘图的标准颜色是什么?

发布于 2024-10-25 09:31:28 字数 1327 浏览 2 评论 0 原文

注意:此问题的所有答案对于版本 10 之前的 Mathematica 版本均有效。对于版本 10 及更高版本,请参阅 https://mathematica.stackexchange.com/questions/54486/how-to-access-new-colour-schemes-in-version -10https:// /mathematica.stackexchange.com/questions/54629/what-are-the-standard-colors-for-plots-in-mathematica-10。)

当使用绘图Mathematica 中的 >ListPlot 命令,选择某些默认颜色。

出于某些报告中统一性的原因,我想将它们与 PlotStyle 选项一起使用。事实证明,我无法使用预定义的颜色名称重现默认颜色,尽管蓝色和紫色似乎在某种程度上很接近。

因此我的问题是:

<块引用>

如何选择 Mathematica 在绘图中与 PlotStyle 一起使用的标准颜色?

先感谢您。

很好的答案belisariusSjoerd 从中我们可以得出结论:

<块引用>

Plot[Sin[x], {x, 0, 2 Pi}, PlotStyle ->颜色数据[1, 4]]

将导致以第四个标准颜色(一些漂亮的绿色)绘制正弦。

(Note: All the answers to this question are valid for versions of Mathematica before version 10. For versions 10 and above, see https://mathematica.stackexchange.com/questions/54486/how-to-access-new-colour-schemes-in-version-10 and https://mathematica.stackexchange.com/questions/54629/what-are-the-standard-colors-for-plots-in-mathematica-10.)

When using the Plot or ListPlot command in Mathematica, certain default colors are chosen.

For reasons of uniformity within some report I would like to use them along with the PlotStyle option. It turned out that I cannot reproduce the default colors with the pre-defined color names, although blue and purple seem to be somehow close.

Hence my question:

How can I chose the standard colors used by Mathematica in plots along with PlotStyle?

Thank you in advance.

Nice answers were given by belisarius and Sjoerd from which we can conclude that

Plot[Sin[x], {x, 0, 2 Pi}, PlotStyle -> ColorData[1, 4]]

will result in a sine plotted in the fourth standard color, some nice green.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

赠意 2024-11-01 09:31:28

我知道这确实迟到了,但是用于生成 ColorData[1]< 中的第 n 颜色的表达式/code> 是:

Hue[FractionalPart[0.67 + 2.0 (i - 1)/GoldenRatio], 0.6, 0.6]

更新 根据下面 Alexey 的评论,您可以使用以下命令找到它:

ColorData[1] // InputForm

I know this is really late to the game, but the expression used to generate the nth color in ColorData[1] is:

Hue[FractionalPart[0.67 + 2.0 (i - 1)/GoldenRatio], 0.6, 0.6]

Update Based on Alexey's comment below, you can find this using:

ColorData[1] // InputForm
寒江雪… 2024-11-01 09:31:28

Plot 使用的颜色位于 ColorData[1] 中。

比较

Graphics[MapIndexed[{#1, 
    Tooltip[Rectangle[{#2[[1]], 0}, {#2[[1]] + 1, 1}], #1]} &, 
  ColorData[1] /@ Range[40]]]

在此处输入图像描述

贝利萨留的颜色

Graphics[MapIndexed[{#1, 
    Tooltip[Rectangle[{#2[[1]], 0}, {#2[[1]] + 1, 1}], #1]} &, 
  Cases[ListPlot[Table[{i}, {i, 40}]], Hue[x__], Infinity]]]

enter image description here

它们是相同的,除了一个是 Hue 术语,另一个是 RGBColor 术语

The colors used by Plot are in ColorData[1].

Compare

Graphics[MapIndexed[{#1, 
    Tooltip[Rectangle[{#2[[1]], 0}, {#2[[1]] + 1, 1}], #1]} &, 
  ColorData[1] /@ Range[40]]]

enter image description here

with Belisarius' colors

Graphics[MapIndexed[{#1, 
    Tooltip[Rectangle[{#2[[1]], 0}, {#2[[1]] + 1, 1}], #1]} &, 
  Cases[ListPlot[Table[{i}, {i, 40}]], Hue[x__], Infinity]]]

enter image description here

They are the same, except one is terms of Hue and the other in terms or RGBColor

星光不落少年眉 2024-11-01 09:31:28

如果这样做:

ListPlot[Table[{i}, {i, 10}]] // FullForm  

您将获得前 10 个使用的色调。

或者这为您提供了一个随时可用的列表:

hues = Cases[ListPlot[Table[{i}, {i, 10}]], Hue[x__], Infinity]

{Hue[0.67, 0.6, 0.6],     Hue[0.906068, 0.6, 0.6], 
 Hue[0.142136, 0.6, 0.6], Hue[0.378204, 0.6, 0.6], 
 Hue[0.614272, 0.6, 0.6], Hue[0.85034, 0.6, 0.6], 
 Hue[0.0864079, 0.6, 0.6],Hue[0.322476, 0.6, 0.6], 
 Hue[0.558544, 0.6, 0.6], Hue[0.794612, 0.6, 0.6]}  

使用示例:

SphericalPlot3D[\[Phi], {\[Theta], 0, Pi}, {\[Phi], 0, 3 Pi},
 Epilog -> 
  Table[Inset[Framed[Style["Spiral", 20],
        Background -> hues[[i]]],
             {i/15 + .1, i/15}], 
  {i, 10}]]  

在此处输入图像描述

如果您更喜欢 RGB 色彩空间,您可以做:

rgbs= ColorConvert[#, "RGB"] & /@ hues

**编辑 ** 与 Eli 的公式相比:

mine = Cases[ListPlot[Table[{i}, {i, 10}]], Hue[x__], Infinity]
elis = Table[Hue[FractionalPart[0.67 + 2.0 (i-1)/GoldenRatio],0.6,0.6], {i,1,10}]
Chop[(mine- elis) /. Hue[x_, __] -> x]
(* -> {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} *)

太棒了,Eli!

If you do:

ListPlot[Table[{i}, {i, 10}]] // FullForm  

You get the first 10 Hues used.

Or this gives you a ready to use list:

hues = Cases[ListPlot[Table[{i}, {i, 10}]], Hue[x__], Infinity]

{Hue[0.67, 0.6, 0.6],     Hue[0.906068, 0.6, 0.6], 
 Hue[0.142136, 0.6, 0.6], Hue[0.378204, 0.6, 0.6], 
 Hue[0.614272, 0.6, 0.6], Hue[0.85034, 0.6, 0.6], 
 Hue[0.0864079, 0.6, 0.6],Hue[0.322476, 0.6, 0.6], 
 Hue[0.558544, 0.6, 0.6], Hue[0.794612, 0.6, 0.6]}  

Usage sample:

SphericalPlot3D[\[Phi], {\[Theta], 0, Pi}, {\[Phi], 0, 3 Pi},
 Epilog -> 
  Table[Inset[Framed[Style["Spiral", 20],
        Background -> hues[[i]]],
             {i/15 + .1, i/15}], 
  {i, 10}]]  

enter image description here

If you prefer the RGB color space you may do:

rgbs= ColorConvert[#, "RGB"] & /@ hues

**Edit ** Comparing with Eli's formula:

mine = Cases[ListPlot[Table[{i}, {i, 10}]], Hue[x__], Infinity]
elis = Table[Hue[FractionalPart[0.67 + 2.0 (i-1)/GoldenRatio],0.6,0.6], {i,1,10}]
Chop[(mine- elis) /. Hue[x_, __] -> x]
(* -> {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} *)

Great, Eli!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文