Opened 9 years ago
Closed 2 years ago
#12591 closed defect (duplicate)
same color shows up different in graphics_array
Reported by:  dkrenn  Owned by:  jason, was 

Priority:  major  Milestone:  sageduplicate/invalid/wontfix 
Component:  graphics  Keywords:  graphics_array, color 
Cc:  kcrisman, mkoeppe  Merged in:  
Authors:  Frédéric Chapoton  Reviewers:  Eric Gourgoulhon 
Report Upstream:  N/A  Work issues:  
Branch:  u/chapoton/12591 (Commits, GitHub, GitLab)  Commit:  2e42e380f503eed00fd29a168dcc402144dfb9d3 
Dependencies:  Stopgaps: 
Description (last modified by )
The code
g = circle((0,0),1,rgbcolor='red',fill=True, alpha=0.5) graphics_array([g,g,g]).show()
produces three circles, the first two with color 0xFF7F7F (htmlcolorcode), the third one with color 0xFF3F3F (htmlcolorcode). But all three should have the same color.
This was reported on the public bug reports from the notebook interface by Daniel Krenn on 12/22/2010
Change History (24)
comment:1 Changed 9 years ago by
 Description modified (diff)
comment:2 Changed 9 years ago by
comment:3 followup: ↓ 16 Changed 9 years ago by
In fact, there is another manifestation of this there.
Replying to [comment:3 eviatarbach]: > This is also a problem with other options, such as tick_formatter, ticks, and axes_labels. They are only applied to the last graphic; see attached image produced by the following code: > graphics_array([plot(sin(B*x), xmin=2*pi, xmax=2*pi, tick_formatter=pi, ticks=pi/2, axes_labels=('', '%s'%B)) for B in [2,1,1/2,1/2,1,2]], 3, 2)
comment:4 Changed 8 years ago by
 Milestone changed from sage5.11 to sage5.12
comment:5 Changed 7 years ago by
 Milestone changed from sage6.1 to sage6.2
comment:6 Changed 7 years ago by
 Milestone changed from sage6.2 to sage6.3
comment:7 Changed 7 years ago by
 Milestone changed from sage6.3 to sage6.4
comment:8 Changed 7 years ago by
It seems that the last one is just duplicated (which looks the same as doubling alpha).
sage: g = circle((0,0),1,rgbcolor='red',fill=True, alpha=0.1) sage: graphics_array([g,g,g]).show()
comment:9 Changed 7 years ago by
More serious proof of duplication of the last object of the group:
sage: g = circle((0,0),1,rgbcolor='red',fill=True, alpha=0.1, legend_label='pink') sage: graphics_array([g,g,g]).show()
But where on earth does this duplication come from ?
comment:10 Changed 7 years ago by
 Branch set to u/chapoton/12591
 Cc kcrisman added
 Commit set to 0aa089a5e1a800600ef38af6198782db16fabc03
 Status changed from new to needs_review
The culprit was the line
g.save(filename, dpi=dpi, figure=figure, sub=subplot, verify=do_verify, axes=axes, **kwds)
in sage/plot/graphics.py. Here g was defined inside the previous loop, so after the loop it gets once again the last value.
I have just extracted the last object by stopping the loop one step before.
New commits:
0aa089a  trac #12591 workaround against duplication of last object in graphics_array

comment:11 Changed 7 years ago by
comment:12 Changed 7 years ago by
Probably all this happens at the very same place, but I do not understand this matplotlib business, so I am not able to do better than what I did.
comment:13 followup: ↓ 14 Changed 7 years ago by
Note that the legend in the third picture is no longer duplicated, but does not look the same:
sage: g = circle((0,0),1,rgbcolor='red',fill=True, alpha=0.1, legend_label='pink') sage: graphics_array([g,g,g]).show()
comment:14 in reply to: ↑ 13 ; followup: ↓ 15 Changed 7 years ago by
 Status changed from needs_review to needs_work
Note that the legend in the third picture is no longer duplicated, but does not look the same:
sage: g = circle((0,0),1,rgbcolor='red',fill=True, alpha=0.1, legend_label='pink') sage: graphics_array([g,g,g]).show()
Noted. I tried getting rid of that last call to save
and instead doing all in the loop, but that didn't work. Probably we'll need to directly import stuff like
from matplotlib.backends.backend_agg import FigureCanvasAgg figure.set_canvas(FigureCanvasAgg(figure)) # this messes up the aspect ratio! #figure.canvas.mpl_connect('draw_event', pad_for_tick_labels) # tight_layout adjusts the *subplot* parameters so ticks aren't cut off, etc. figure.tight_layout() opts = dict(dpi=dpi, transparent=transparent) if fig_tight is True: opts['bbox_inches'] = 'tight' if self._bbox_extra_artists: opts['bbox_extra_artists'] = self._bbox_extra_artists figure.savefig(filename, **opts)
from the singular graphics object save code.
comment:15 in reply to: ↑ 14 Changed 7 years ago by
Noted. I tried getting rid of that last call to
save
and instead doing all in the loop, but that didn't work. Probably we'll need to directly import stuff like <snip> from the singular graphics object save code.
Yes, this works, though one has to (for now) get rid of the transparent and I just got rid of the last two if clauses since they didn't seem relevant to the array case for now.
comment:16 in reply to: ↑ 3 Changed 7 years ago by
But there is a problem...
In fact, there is another manifestation of this there.
> graphics_array([plot(sin(B*x), xmin=2*pi, xmax=2*pi, tick_formatter=pi, ticks=pi/2, axes_labels=('', '%s'%B)) for B in [2,1,1/2,1/2,1,2]], 3, 2)
Actually, it turns out that fixing this ticket makes that issue even worse. It's only in that save command which I just removed that all these extra options get used at all! So the "right" fix for this would fix both; the current fix would leave that the same but still have the problem mentioned.
Your current fix, though, as far as I can tell, doesn't really make things worse, because for me in vanilla Sage I get for the command you mention in this comment
Note that the legend in the third picture is no longer duplicated, but does not look the same:
that it just has two of the weird legends, so one weird legend is better than duplicated weird legends, right?
Let me know what you think; properly doctested (well, mentioned in a tests section, though perhaps we could extract the last element of a graphics array and check that it just has one figure), this change is a step in the right direction, I think.
comment:17 Changed 6 years ago by
 Milestone changed from sage6.4 to sage6.8
comment:18 Changed 5 years ago by
 Milestone changed from sage6.8 to sage7.2
comment:19 Changed 4 years ago by
 Cc mkoeppe added
comment:20 Changed 4 years ago by
 Commit changed from 0aa089a5e1a800600ef38af6198782db16fabc03 to 2e42e380f503eed00fd29a168dcc402144dfb9d3
Branch pushed to git repo; I updated commit sha1. New commits:
2e42e38  Merge branch 'u/chapoton/12591' in 8.1.b5

comment:21 Changed 2 years ago by
The issues described here are fixed in #27865.
comment:22 Changed 2 years ago by
 Milestone changed from sage7.2 to sageduplicate/invalid/wontfix
 Status changed from needs_work to needs_review
comment:23 Changed 2 years ago by
 Reviewers set to Eric Gourgoulhon
 Status changed from needs_review to positive_review
comment:24 Changed 2 years ago by
 Resolution set to duplicate
 Status changed from positive_review to closed
Huh, that's interesting. Apparently the
alpha
is not propogated to the last one.Related tickets: #10657 and friends.