我想用python中的PyX
包制作一个密度图。
我用密码
from pyx import *
import numpy
import math
from pyx.graph import axis
g = graph.graphxy(height=8, width=8,
x=graph.axis.linear(min=0.0, max=2.0, title=r"$x-axis$"),
y=graph.axis.linear(min=0.0, max=2.0, title=r'$y-axis$'))
g.plot(graph.data.file("datatotest.dat", xmin=1, xmax=2, ymin=3, ymax=4, color=5, title=r"$bar$"),
[graph.style.rect(gradient=color.gradient.Gray)]
)
g.writePDFfile()
我用数据
0 1 0 1 0.12
0 1 1 2 0.56
1 2 0 1 0.98
1 2 1 2 0.23
我得到了结果
我想要更有趣的颜色。
但是使用color.gradient.Rainbow
会给出错误消息:
“hsb颜色不可用的颜色空间字符串”
。
例如,对于color.gradient.Hue.
和使用反向时,我会得到类似的错误。
问:这里除了灰度外,还有什么其他颜色梯度?
发布于 2020-09-12 14:42:26
这个问题是由于右边的梯度和这里使用位图进行优化以获得良好的压缩。不幸的是,位图不适用于HSB颜色。现在,解决方案相当容易,因为有彩虹(和其他梯度)转换成不同的颜色空间。在这种情况下,您可以使用color.rgbgradient.Rainbow或color.cmykgradient.Rainbow等,这取决于您希望输出的颜色空间。
发布于 2020-09-16 07:09:18
我曾经做过类似的事情。我为一些与seaborn.heatmap相关的数据创建了一个热图,您应该试试这个。https://seaborn.pydata.org/generated/seaborn.heatmap.html
https://stackoverflow.com/questions/63784602
复制相似问题