问题描述
我想用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,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.
会出现类似的错误。
问题:除了灰色以外,还有什么其他的颜色渐变在这里起作用?
解决方法
该问题是由于右侧的渐变以及此处使用位图进行的优化以实现良好压缩所致。不幸的是,位图不适用于HSB颜色。现在,解决方案相当简单,因为彩虹(和其他渐变)也转换为不同的色彩空间。根据您的情况,您可以使用color.rgbgradient.Rainbow或color.cmykgradient.Rainbow等,具体取决于要在输出中使用的颜色空间。
,我曾经做过类似的事情。我为seaborn.heatmap创建了一些数据关联的热图,您应该尝试一下。 https://seaborn.pydata.org/generated/seaborn.heatmap.html