python-visualization/branca

Customizing Size of LinearColormap

zeyaddeeb opened this issue · 5 comments

Is there a way to resize the colormap?

'<svg height="50" width="500">' +

I'm testing this on mobile and it looks a bit off.

I was running into this, too. The _repr_html_() method uses a fixed width of 500, which is a bit unfortunate because one cannot use it in an arbitrary context. See this image.

heatmap_colormaps

It would be nice to give the colormap instances a width attribute that could be used by the _repr_html_() method. A workaround would be to scale the returned SVG which you can using code below, but it will also scale the number labels:

import io
from branca.colormap import step
from ipywidgets import HTML
from reportlab.graphics.renderSVG import drawToString
from svglib.svglib import svg2rlg

colmap = step.Accent_03
drawing = svg2rlg(io.StringIO((colmap._repr_html_())))
drawing.scale(0.5, 1)
scaled_svg = drawToString(drawing)
HTML(scaled_svg)

You're right that currently the color scales have a fixed size. I get that you may want to change that. While looking into this I tried something out to add this functionality. Maybe you want to test it?

If we scale the thing, is the numbers also resizing a good or a bad thing?

Scaled (squeezed or stretched) would be very ugly. One might want to drop them entirely and leave only ticks as an option. In the end it’s a simple mini plot with its own axis which can easily mean introducing a bunch of config options...

Okay so no scaling then. Can you check out #77, see if that works for you?

I'll try, but I don't see any info about building it locally.