Python Pyx: color.gradient for graph.style.rect

214 views Asked by At

I wanna make a density plot with PyX package in python.

I use the code

 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()

and I use the data

 0  1   0   1   0.12
 0  1   1   2   0.56
 1  2   0   1   0.98
 1  2   1   2   0.23

and I get the result

enter image description here

I wanna have more interesting colors.

But using color.gradient.Rainbow gives the error message:

"colorspace string not available for hsb colors"

.

I get similar error for color.gradient.Hue. and when using Reverse for example.

Question: What other color gradient other than gray work here?

2

There are 2 answers

0
wobsta On BEST ANSWER

The problem is due to the gradient on the right side and the optimization using a bitmap here for good compression. Bitmaps are not available for HSB colors, unfortunately. Now, the solution is rather easy, as there are rainbow (and other gradients) converted to different color spaces as well. In your case, you can use color.rgbgradient.Rainbow or color.cmykgradient.Rainbow etc. depending on which color space you want to have in your output.

0
user123 On

i have done something similar once. i created a heatmap for some correlation of data with seaborn.heatmap you should try this out. https://seaborn.pydata.org/generated/seaborn.heatmap.html