You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Request: for non-interactive backends make fig.canvas.draw() force the render #16558
When using a non-interactive backend (specifically the PGF backend), I noticed that fig.canvas.draw() isn’t equivalent to fig.draw(fig.canvas.get_renderer()). Can anyone please explain the difference between these two approaches?
(this has been answered) Please see the explanation by @tacaswell on discourse.
Reproducing the last part of the response since it is potentially an actionable item
I suspect that we should add code to the draw methods of the non-interactive backends to force the render, but that needs a bit of thought to make sure we don’t have any unintended consequences of that.
changed the title [-]Feature request: for non-interactive backends make fig.canvas.draw() force the render[/-][+]Request: for non-interactive backends make fig.canvas.draw() force the render[/+]on Feb 19, 2020
Yes, I will put up a stripped down version of my use-case tomorrow.
In a nutshell, I was using constrained layout to get “nice” axes positions
( To get axes positions I needed to trigger the draw — and I noticed that
fig.canvas.draw() didn’t work for pgf backend) —> saving the axes positions
—-> turning off the constrained layout —-> adding an artist to the figure
with ‘set in layout’ set to False (to not mess up the layout).
On Wed, Feb 19, 2020 at 11:42 PM Thomas A Caswell ***@***.***> wrote:
I assume the use-case here is to then adjust things where you need to know
what ticks are picked, text sizes, ect?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#16558?email_source=notifications&email_token=ADTY7RB4U7UI7J4SFNMBWBTRDYC3BA5CNFSM4KX7XNP2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMKWWVY#issuecomment-588606295>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADTY7RF2BYB2BQIGUCWSUE3RDYC3BANCNFSM4KX7XNPQ>
.
Please ignore my earlier response ... I was half asleep when I responded via email :D
Here is a stripped-down (maybe not so stripped-down?) version of my use-case
importnumpyasnpimportmatplotlib.pyplotaspltplt.switch_backend('pgf') # Switching to the PGF backendfig, ax=plt.subplots(figsize=(6, 3.0), ncols=2, nrows=1,
constrained_layout=True, sharey=True)
fig.set_constrained_layout_pads(wspace=0.03)
ax[0].plot(np.arange(4), 'r', label=r'Really longgggg label 1')
ax[1].plot(np.arange(5), 'b', label=r'Really longgggg label 2')
(leg_h0, leg_lab0) =ax[0].get_legend_handles_labels()
(leg_h1, leg_lab1) =ax[1].get_legend_handles_labels()
# add a legend to one of the axes to make space at the top of the figureleg0=ax[0].legend(leg_h0, leg_lab0, loc='lower center',
bbox_to_anchor=(0.5, 1.07))
leg0.set_in_layout(True) # force to steal space from top of the figure# ------------------------------------------------------# Trigger a draw (required for constrained_layout to work)# fig.canvas.draw() # Doesn't work!fig.draw(fig.canvas.get_renderer()) # works!# ------------------------------------------------------# Thanks constrained_layout, your work is done! turning you off nowfig.set_constrained_layout(False)
# Remove legend from axes and add a figure legend# which includes entries from both axesleg0.remove()
fig_leg=fig.legend(*zip(leg_h0, leg_h1), *zip(leg_lab0, leg_lab1),
loc='lower center', ncol=2, columnspacing=5,
bbox_to_anchor=(0.5, 0.85))
fig.savefig('test.png', dpi=200)
Would you want to take a crack at implementing this?
I think the upside (that fig.canvas.draw always does the same thing) outweighs the downside (the biggest risk I see is someone relying on draw and draw_idle being no-ops when run with a non-interactive backend but wanting them there on an alternate interactive usage).
On Thu, Feb 20, 2020 at 3:23 PM Thomas A Caswell ***@***.***> wrote:
Would you want to take a crack at implementing this?
I think the upside (that fig.canvas.draw always does the same thing)
outweighs the downside (the biggest risk I see is someone relying on draw
and draw_idle being no-ops when run with a non-interactive backend *but*
wanting them there on an alternate interactive usage).
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#16558?email_source=notifications&email_token=ADTY7RH45EDVYRRRX4OWZFDRD3RFDA5CNFSM4KX7XNP2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMP54EQ#issuecomment-589291026>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADTY7RHVK6E2WK6GUN2ZY7LRD3RFDANCNFSM4KX7XNPQ>
.
Having an implementation would be good to move the conversation along. I don't think this will be a tremendous amount of work and having a concrete implementation will make it easier to think about.
Activity
[-]Feature request: for non-interactive backends make fig.canvas.draw() force the render[/-][+]Request: for non-interactive backends make fig.canvas.draw() force the render[/+]tacaswell commentedon Feb 20, 2020
I assume the use-case here is to then adjust things where you need to know what ticks are picked, text sizes, ect?
pharshalp commentedon Feb 20, 2020
pharshalp commentedon Feb 20, 2020
Please ignore my earlier response ... I was half asleep when I responded via email :D
Here is a stripped-down (maybe not so stripped-down?) version of my use-case
tacaswell commentedon Feb 20, 2020
Would you want to take a crack at implementing this?
I think the upside (that
fig.canvas.drawalways does the same thing) outweighs the downside (the biggest risk I see is someone relying ondrawanddraw_idlebeing no-ops when run with a non-interactive backend but wanting them there on an alternate interactive usage).pharshalp commentedon Feb 20, 2020
tacaswell commentedon Feb 20, 2020
Having an implementation would be good to move the conversation along. I don't think this will be a tremendous amount of work and having a concrete implementation will make it easier to think about.
pharshalp commentedon Feb 17, 2021
closed by #18408