Opened 11 years ago
Closed 3 years ago
#12591 closed defect (duplicate)
same color shows up different in graphics_array
Reported by:  Daniel Krenn  Owned by:  jason, was 

Priority:  major  Milestone:  sageduplicate/invalid/wontfix 
Component:  graphics  Keywords:  graphics_array, color 
Cc:  KarlDieter Crisman, Matthias Köppe  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 11 years ago by
Description:  modified (diff) 

comment:2 Changed 11 years ago by
comment:3 followup: 16 Changed 11 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 9 years ago by
Milestone:  sage5.11 → sage5.12 

comment:5 Changed 9 years ago by
Milestone:  sage6.1 → sage6.2 

comment:6 Changed 8 years ago by
Milestone:  sage6.2 → sage6.3 

comment:7 Changed 8 years ago by
Milestone:  sage6.3 → sage6.4 

comment:8 Changed 8 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 8 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 8 years ago by
Authors:  → Frédéric Chapoton 

Branch:  → u/chapoton/12591 
Cc:  KarlDieter Crisman added 
Commit:  → 0aa089a5e1a800600ef38af6198782db16fabc03 
Status:  new → 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 8 years ago by
comment:12 Changed 8 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 8 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 followup: 15 Changed 8 years ago by
Status:  needs_review → 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 Changed 8 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 Changed 8 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 7 years ago by
Milestone:  sage6.4 → sage6.8 

comment:18 Changed 7 years ago by
Milestone:  sage6.8 → sage7.2 

comment:19 Changed 5 years ago by
Cc:  Matthias Köppe added 

comment:20 Changed 5 years ago by
Commit:  0aa089a5e1a800600ef38af6198782db16fabc03 → 2e42e380f503eed00fd29a168dcc402144dfb9d3 

Branch pushed to git repo; I updated commit sha1. New commits:
2e42e38  Merge branch 'u/chapoton/12591' in 8.1.b5

comment:22 Changed 3 years ago by
Milestone:  sage7.2 → sageduplicate/invalid/wontfix 

Status:  needs_work → needs_review 
comment:23 Changed 3 years ago by
Reviewers:  → Eric Gourgoulhon 

Status:  needs_review → positive_review 
comment:24 Changed 3 years ago by
Resolution:  → duplicate 

Status:  positive_review → closed 
Huh, that's interesting. Apparently the
alpha
is not propogated to the last one.Related tickets: #10657 and friends.