background=None should be transparent

Bug #339754 reported by Michael Wayne Goodman
2
Affects Status Importance Assigned to Milestone
Cairo Plot
Fix Committed
Low
Rodrigo Moreira Araújo

Bug Description

For any given plot, saying background=None should cause there to be *no* background (that is, fully transparent). This might only be applicable for certain filetypes, but I think png, svg, ps, and pdf can all handle it.

The default white-to-gray background should be accessible by one of the color-themes.

Revision history for this message
Rodrigo Moreira Araújo (alf-rodrigo) wrote :

What you're saying is correct.
This problem will be addressed when pre-set backgrounds are implemented this week.

Changed in cairoplot:
assignee: nobody → alf-rodrigo
importance: Undecided → Low
status: New → Confirmed
Revision history for this message
Rodrigo Moreira Araújo (alf-rodrigo) wrote :

I don't think the default should be fully transparent as it's less needed than the white-to-gray.
That said, on revision 30 the white-to-gray background is still the default, but it's now possible to pass color strings for the background. Whenever you wish a transparent background, just pass it like this:

data = [1,2,3,4,5,6,7,8,9,10,11,12,13,14]
cairoplot.vertical_bar_plot ( 'bar_background_color', data, 400, 300, background = "transparent", border = 20, grid = True)

Changed in cairoplot:
status: Confirmed → Fix Committed
Revision history for this message
Michael Wayne Goodman (goodmami) wrote :

Thanks for your attention to all the bugs I submitted (there'll be more ^^)

I never said that transparent should be the default (even though for me it's much more needed than white-to-gray, as I am using these charts for academic papers written in LaTeX). It's just more semantically accurate and understandable if "background=None" means "No background" than to mean "Default white-to-gray background". By all means have the gradient be the default, but just change the class as follows:

default_background = cairo.LinearGradient(self.width / 2, 0, self.width / 2, self.height)
default_background.add_color_stop_rgba(0,1.0,1.0,1.0,1.0)
default_background.add_color_stop_rgba(1.0,0.9,0.9,0.9,1.0)

...

class Plot(object):
    def __init__(self,
                 ...
                 background=default_background,
                 .... )
    ...
    def set_background(self, background):
        if background is None:
            # do whatever is done in rev 30 for background="transparent"
        ....

or to be even more explicit, you could call it "white_to_gray_gradient" instead of "default_background". But the benefit in using "default_background" is that the user could override it and not have to set a new background for every plot if they are making many at once. Eg, I could say:

cairoplot.default_background=None
cairoplot.vertical_bar_plot(...)
cairoplot.donut_plot(...)
...

And they would all use the new default_background, which I set to None (which I argue should be transparent).

Does this make sense?

Revision history for this message
Rodrigo Moreira Araújo (alf-rodrigo) wrote :

Once again you stand correct.
Sorry as I misunderstood your initial ideas by thinking you were pointing the transparent background to default.
I'll add the gradient support to my background theme solution and add the default_background global variable to work as you said.

I'm glad to know you're using CairoPlot with Latex. How is it working? I haven't heard of anyone who had tried this.
And thanks for all these bugs. Please, keep them coming.

Changed in cairoplot:
status: Fix Committed → In Progress
Revision history for this message
Michael Wayne Goodman (goodmami) wrote :

About the bug: that's good to hear, but I hope I'm not being too pushy.

About LaTeX: I've used CairoPlot in a LaTeX/Beamer presentation, which worked fairly well, but as of yet it's been inconvenient for use in papers. I saw a blog post about embedding Python in LaTeX (http://www.texample.net/weblog/2008/oct/24/embedding-python-latex/) and decided to give CairoPlot another attempt. While usable in it's current form, If a handful of things get implemented (transparent bg (which you said is already in rev 30), legend/key for bar charts, .eps output support, and length dimensions (eg 3cm, 2in, 0.5em, etc)), then CairoPlot would be nearly perfect for my needs. (Note those last two are bugs I haven't filed yet).

Thanks for the wonderful package, and I hope to be contributing code as well as ideas soon.

Revision history for this message
Rodrigo Moreira Araújo (alf-rodrigo) wrote :

You're not being too pushy. Please keep the bugs coming.

About the bug itself now. On revision 31 background=None now means transparent background but the default is still the white to light_gray background. Background can now be changed using two other methods:

background = "red" #or any other color name
background = "red white blue" #or any other combination of colors separated by space

The first option will set that solid_color as the background. The second one will create a new linear_gradient object using the colors passed and use it as background.

Concerning the idea of a cairoplot.default_background, I'll postpone it for a while until I give its consequences further thought.

Thanks for all these ideas! :D

Changed in cairoplot:
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.