Sage: Ticket #12591: same color shows up different in graphics_array
https://trac.sagemath.org/ticket/12591
<p>
The code
</p>
<pre class="wiki">g = circle((0,0),1,rgbcolor='red',fill=True, alpha=0.5)
graphics_array([g,g,g]).show()
</pre><p>
produces three circles, the first two with color 0xFF7F7F (html-color-code), the third one with color 0xFF3F3F (html-color-code). But all three should have the same color.
</p>
<p>
This was reported on <a class="ext-link" href="https://spreadsheets.google.com/pub?key=pCwvGVwSMxTzT6E2xNdo5fA"><span class="icon"></span>the public bug reports from the notebook interface</a> by Daniel Krenn on 12/22/2010
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/12591
Trac 1.1.6dkrennSun, 26 Feb 2012 19:20:48 GMTdescription changed
https://trac.sagemath.org/ticket/12591#comment:1
https://trac.sagemath.org/ticket/12591#comment:1
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/12591?action=diff&version=1">diff</a>)
</li>
</ul>
TicketkcrismanMon, 27 Feb 2012 15:57:14 GMT
https://trac.sagemath.org/ticket/12591#comment:2
https://trac.sagemath.org/ticket/12591#comment:2
<p>
Huh, that's interesting. Apparently the <code>alpha</code> is not propogated to the last one.
</p>
<p>
Related tickets: <a class="closed ticket" href="https://trac.sagemath.org/ticket/10657" title="defect: options for items in a GraphicsArray() should be set independently (closed: fixed)">#10657</a> and friends.
</p>
TicketkcrismanMon, 27 Feb 2012 15:58:57 GMT
https://trac.sagemath.org/ticket/12591#comment:3
https://trac.sagemath.org/ticket/12591#comment:3
<p>
In fact, there is another manifestation of this there.
</p>
<pre class="wiki">
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)
</pre>
TicketjdemeyerTue, 13 Aug 2013 15:35:53 GMTmilestone changed
https://trac.sagemath.org/ticket/12591#comment:4
https://trac.sagemath.org/ticket/12591#comment:4
<ul>
<li><strong>milestone</strong>
changed from <em>sage-5.11</em> to <em>sage-5.12</em>
</li>
</ul>
Ticketvbraun_spamThu, 30 Jan 2014 21:20:52 GMTmilestone changed
https://trac.sagemath.org/ticket/12591#comment:5
https://trac.sagemath.org/ticket/12591#comment:5
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.1</em> to <em>sage-6.2</em>
</li>
</ul>
Ticketvbraun_spamTue, 06 May 2014 15:20:58 GMTmilestone changed
https://trac.sagemath.org/ticket/12591#comment:6
https://trac.sagemath.org/ticket/12591#comment:6
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.2</em> to <em>sage-6.3</em>
</li>
</ul>
Ticketvbraun_spamSun, 10 Aug 2014 16:51:03 GMTmilestone changed
https://trac.sagemath.org/ticket/12591#comment:7
https://trac.sagemath.org/ticket/12591#comment:7
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.3</em> to <em>sage-6.4</em>
</li>
</ul>
TicketchapotonSun, 02 Nov 2014 20:34:36 GMT
https://trac.sagemath.org/ticket/12591#comment:8
https://trac.sagemath.org/ticket/12591#comment:8
<p>
It seems that the last one is just duplicated (which looks the same as doubling alpha).
</p>
<pre class="wiki">sage: g = circle((0,0),1,rgbcolor='red',fill=True, alpha=0.1)
sage: graphics_array([g,g,g]).show()
</pre>
TicketchapotonMon, 03 Nov 2014 20:51:04 GMT
https://trac.sagemath.org/ticket/12591#comment:9
https://trac.sagemath.org/ticket/12591#comment:9
<p>
More serious proof of duplication of the last object of the group:
</p>
<pre class="wiki">sage: g = circle((0,0),1,rgbcolor='red',fill=True, alpha=0.1, legend_label='pink')
sage: graphics_array([g,g,g]).show()
</pre><p>
But where on earth does this duplication come from ?
</p>
TicketchapotonTue, 04 Nov 2014 13:28:29 GMTstatus changed; commit, cc, branch, author set
https://trac.sagemath.org/ticket/12591#comment:10
https://trac.sagemath.org/ticket/12591#comment:10
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
<li><strong>commit</strong>
set to <em>0aa089a5e1a800600ef38af6198782db16fabc03</em>
</li>
<li><strong>cc</strong>
<em>kcrisman</em> added
</li>
<li><strong>branch</strong>
set to <em>u/chapoton/12591</em>
</li>
<li><strong>author</strong>
set to <em>Frédéric Chapoton</em>
</li>
</ul>
<p>
The culprit was the line
</p>
<pre class="wiki"> g.save(filename, dpi=dpi, figure=figure, sub=subplot,
verify=do_verify, axes=axes, **kwds)
</pre><p>
in sage/plot/graphics.py. Here g was defined inside the previous loop, so after the loop it gets once again the last value.
</p>
<p>
I have just extracted the last object by stopping the loop one step before.
</p>
<hr />
<p>
New commits:
</p>
<table class="wiki">
<tr><td><a class="ext-link" href="http://git.sagemath.org/sage.git/commit/?id=0aa089a5e1a800600ef38af6198782db16fabc03"><span class="icon"></span>0aa089a</a></td><td><code>trac #12591 workaround against duplication of last object in graphics_array</code>
</td></tr></table>
TicketkcrismanTue, 04 Nov 2014 14:41:22 GMT
https://trac.sagemath.org/ticket/12591#comment:11
https://trac.sagemath.org/ticket/12591#comment:11
<p>
Huh, nice find! Do you think this would go toward fixing <a class="closed ticket" href="https://trac.sagemath.org/ticket/10657" title="defect: options for items in a GraphicsArray() should be set independently (closed: fixed)">#10657</a> or <a class="closed ticket" href="https://trac.sagemath.org/ticket/11160" title="defect: Graphics Array needs suboptions to show (closed: duplicate)">#11160</a>?
</p>
TicketchapotonTue, 04 Nov 2014 19:30:19 GMT
https://trac.sagemath.org/ticket/12591#comment:12
https://trac.sagemath.org/ticket/12591#comment:12
<p>
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.
</p>
TicketchapotonTue, 04 Nov 2014 19:33:04 GMT
https://trac.sagemath.org/ticket/12591#comment:13
https://trac.sagemath.org/ticket/12591#comment:13
<p>
Note that the legend in the third picture is no longer duplicated, but does not look the same:
</p>
<pre class="wiki">sage: g = circle((0,0),1,rgbcolor='red',fill=True, alpha=0.1, legend_label='pink')
sage: graphics_array([g,g,g]).show()
</pre>
TicketkcrismanWed, 05 Nov 2014 17:17:24 GMTstatus changed
https://trac.sagemath.org/ticket/12591#comment:14
https://trac.sagemath.org/ticket/12591#comment:14
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>needs_work</em>
</li>
</ul>
<blockquote class="citation">
<p>
Note that the legend in the third picture is no longer duplicated, but does not look the same:
</p>
<pre class="wiki">sage: g = circle((0,0),1,rgbcolor='red',fill=True, alpha=0.1, legend_label='pink')
sage: graphics_array([g,g,g]).show()
</pre></blockquote>
<p>
Noted. I tried getting rid of that last call to <code>save</code> and instead doing all in the loop, but that didn't work. Probably we'll need to directly import stuff like
</p>
<pre class="wiki"> 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)
</pre><p>
from the singular graphics object save code.
</p>
TicketkcrismanWed, 05 Nov 2014 17:24:03 GMT
https://trac.sagemath.org/ticket/12591#comment:15
https://trac.sagemath.org/ticket/12591#comment:15
<blockquote class="citation">
<p>
Noted. I tried getting rid of that last call to <code>save</code> 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.
</p>
</blockquote>
<p>
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.
</p>
TicketkcrismanWed, 05 Nov 2014 17:34:29 GMT
https://trac.sagemath.org/ticket/12591#comment:16
https://trac.sagemath.org/ticket/12591#comment:16
<p>
But there is a problem...
</p>
<blockquote class="citation">
<p>
In fact, there is another manifestation of this there.
</p>
<pre class="wiki">> 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)
</pre></blockquote>
<p>
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.
</p>
<p>
Your current fix, though, as far as I can tell, doesn't really make things <em>worse</em>, because for me in vanilla Sage I get for the command you mention in this comment
</p>
<blockquote class="citation">
<p>
Note that the legend in the third picture is no longer duplicated, but does not look the same:
</p>
</blockquote>
<p>
that it just has two of the weird legends, so one weird legend is better than duplicated weird legends, right?
</p>
<p>
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.
</p>
TicketchapotonFri, 17 Jul 2015 12:05:07 GMTmilestone changed
https://trac.sagemath.org/ticket/12591#comment:17
https://trac.sagemath.org/ticket/12591#comment:17
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.4</em> to <em>sage-6.8</em>
</li>
</ul>
TicketchapotonSun, 27 Mar 2016 17:17:54 GMTmilestone changed
https://trac.sagemath.org/ticket/12591#comment:18
https://trac.sagemath.org/ticket/12591#comment:18
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.8</em> to <em>sage-7.2</em>
</li>
</ul>
TicketmkoeppeMon, 28 Aug 2017 06:26:14 GMTcc changed
https://trac.sagemath.org/ticket/12591#comment:19
https://trac.sagemath.org/ticket/12591#comment:19
<ul>
<li><strong>cc</strong>
<em>mkoeppe</em> added
</li>
</ul>
TicketgitThu, 14 Sep 2017 12:06:23 GMTcommit changed
https://trac.sagemath.org/ticket/12591#comment:20
https://trac.sagemath.org/ticket/12591#comment:20
<ul>
<li><strong>commit</strong>
changed from <em>0aa089a5e1a800600ef38af6198782db16fabc03</em> to <em>2e42e380f503eed00fd29a168dcc402144dfb9d3</em>
</li>
</ul>
<p>
Branch pushed to git repo; I updated commit sha1. New commits:
</p>
<table class="wiki">
<tr><td><a class="ext-link" href="https://git.sagemath.org/sage.git/commit/?id=2e42e380f503eed00fd29a168dcc402144dfb9d3"><span class="icon"></span>2e42e38</a></td><td><code>Merge branch 'u/chapoton/12591' in 8.1.b5</code>
</td></tr></table>
TicketegourgoulhonFri, 24 May 2019 12:43:24 GMT
https://trac.sagemath.org/ticket/12591#comment:21
https://trac.sagemath.org/ticket/12591#comment:21
<p>
The issues described here are fixed in <a class="closed ticket" href="https://trac.sagemath.org/ticket/27865" title="defect: Refactor GraphicsArray, fixing various issues (closed: fixed)">#27865</a>.
</p>
TicketchapotonFri, 28 Jun 2019 12:57:54 GMTstatus, milestone changed
https://trac.sagemath.org/ticket/12591#comment:22
https://trac.sagemath.org/ticket/12591#comment:22
<ul>
<li><strong>status</strong>
changed from <em>needs_work</em> to <em>needs_review</em>
</li>
<li><strong>milestone</strong>
changed from <em>sage-7.2</em> to <em>sage-duplicate/invalid/wontfix</em>
</li>
</ul>
TicketegourgoulhonFri, 28 Jun 2019 16:14:08 GMTstatus changed; reviewer set
https://trac.sagemath.org/ticket/12591#comment:23
https://trac.sagemath.org/ticket/12591#comment:23
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
<li><strong>reviewer</strong>
set to <em>Eric Gourgoulhon</em>
</li>
</ul>
TicketchapotonSun, 30 Jun 2019 11:59:07 GMTstatus changed; resolution set
https://trac.sagemath.org/ticket/12591#comment:24
https://trac.sagemath.org/ticket/12591#comment:24
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>duplicate</em>
</li>
</ul>
Ticket