create account

A note on closing figures in python and a cute cat pic by mathowl

View this thread on: hive.blogpeakd.comecency.com
· @mathowl ·
$2.46
A note on closing figures in python and a cute cat pic
Today I ran into an interesting runtime error using ``matplotlib.pyplot``. This is going to get a bit technical. So if that is not your cup of tea just scroll down to the cute cat pic that deserves upvotes :D 

So ``matplotlib.pyplot`` is commonly used in python to generate any type of plot: bar-charts, histograms, scatter-plots etc. For some applications you might only want to save the figure somewhere in a directory using ``.savefig()`` (and not actually show it using ``.show()``). The weird thing is that if you end your figure generation with ``.savefig()`` the figure is still there even if the program you create saves a new figure. Generally, this won't be a big problem if you have a couple of figures but you might run into memory problems if you have hundreds of them. So it is good practice to close figures and you can do this with ``.close()``. [Here](https://matplotlib.org/2.1.0/api/_as_gen/matplotlib.pyplot.close.html) is the background info on ``.close``.  If you want to ``.show()`` and then ``.close()`` does that work? Well, ``.show()`` blocks ``.close()`` for some reason. So you need to unblock it using ``plt.show(block=False)`` and then you can ``.close()`` it.  Here is a [stack-exchange](https://stackoverflow.com/questions/40395659/view-and-then-close-the-figure-automatically-in-matplotlib) answer with a bit more background.

And now it is time for my cute cat!

<center>
![image.png](https://files.peakd.com/file/peakd-hive/mathowl/5n5KSW6q-image.png)
</center>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 2 others
properties (23)
authormathowl
permlinka-note-on-closing-figures-in-python-and-a-cute-cat-pic
categoryhive-196387
json_metadata"{"app":"peakd/2020.04.5","format":"markdown","description":"About a snake and a cute cat.","tags":["stem","hivecats","python","coding","technical","stemsocial","cat","kitty","cute"],"links":["https://matplotlib.org/2.1.0/api/_as_gen/matplotlib.pyplot.close.html","https://stackoverflow.com/questions/40395659/view-and-then-close-the-figure-automatically-in-matplotlib"],"image":["https://files.peakd.com/file/peakd-hive/mathowl/5n5KSW6q-image.png"]}"
created2020-05-05 13:42:09
last_update2020-05-05 13:42:09
depth0
children7
last_payout2020-05-12 13:42:09
cashout_time1969-12-31 23:59:59
total_payout_value1.250 HBD
curator_payout_value1.209 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,498
author_reputation44,993,635,814,620
root_title"A note on closing figures in python and a cute cat pic"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,200,204
net_rshares5,208,095,504,205
author_curate_reward""
vote details (66)
@bluerobo ·
$0.03
I will have forgotten about this post when it happens to me :(
👍  
properties (23)
authorbluerobo
permlinkre-mathowl-q9vl8e
categoryhive-196387
json_metadata{"tags":["hive-196387"],"app":"peakd/2020.04.5"}
created2020-05-05 20:36:21
last_update2020-05-05 20:36:21
depth1
children1
last_payout2020-05-12 20:36:21
cashout_time1969-12-31 23:59:59
total_payout_value0.016 HBD
curator_payout_value0.016 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length62
author_reputation100,998,068,707,412
root_title"A note on closing figures in python and a cute cat pic"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,207,365
net_rshares96,498,765,031
author_curate_reward""
vote details (1)
@mathowl ·
:(
properties (22)
authormathowl
permlinkqa0q9y
categoryhive-196387
json_metadata{"app":"hiveblog/0.1"}
created2020-05-08 15:13:12
last_update2020-05-08 15:13:12
depth2
children0
last_payout2020-05-15 15:13:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2
author_reputation44,993,635,814,620
root_title"A note on closing figures in python and a cute cat pic"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,260,140
net_rshares0
@chitty ·
I have picked your post for my daily hive voting initiative, Keep it up and Hive On!!
👍  
properties (23)
authorchitty
permlinkre-a-note-on-closing-figures-in-python-and-a-cute-cat-pic-20200509t000522
categoryhive-196387
json_metadata""
created2020-05-09 00:05:24
last_update2020-05-09 00:05:24
depth1
children1
last_payout2020-05-16 00:05:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length86
author_reputation86,901,300,608,582
root_title"A note on closing figures in python and a cute cat pic"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,267,828
net_rshares1,352,533,215
author_curate_reward""
vote details (1)
@mathowl ·
Thank you kind sir. I will get back on track with daily posting.
properties (22)
authormathowl
permlinkqa9dih
categoryhive-196387
json_metadata{"app":"hiveblog/0.1"}
created2020-05-13 07:16:00
last_update2020-05-13 07:16:00
depth2
children0
last_payout2020-05-20 07:16:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length64
author_reputation44,993,635,814,620
root_title"A note on closing figures in python and a cute cat pic"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,343,733
net_rshares0
@jacobtothe ·
Upvoted for the cat. I don't understand Python.
👍  ,
👎  
properties (23)
authorjacobtothe
permlinkre-mathowl-q9v9v2
categoryhive-196387
json_metadata{"tags":["hive-196387"],"app":"peakd/2020.04.5"}
created2020-05-05 16:30:39
last_update2020-05-05 16:30:39
depth1
children1
last_payout2020-05-12 16:30:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length47
author_reputation565,015,996,830,258
root_title"A note on closing figures in python and a cute cat pic"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,203,166
net_rshares-1,452,863,151,775
author_curate_reward""
vote details (3)
@agmoore ·
:)
properties (22)
authoragmoore
permlinkre-jacobtothe-q9y1c5
categoryhive-196387
json_metadata{"tags":["hive-196387"],"app":"peakd/2020.04.5"}
created2020-05-07 04:03:06
last_update2020-05-07 04:03:06
depth2
children0
last_payout2020-05-14 04:03:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2
author_reputation426,712,624,604,558
root_title"A note on closing figures in python and a cute cat pic"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,232,084
net_rshares0
@steemstem ·
re-mathowl-a-note-on-closing-figures-in-python-and-a-cute-cat-pic-20200512t074737867z
<div class='text-justify'> <div class='pull-left'>
 <img src='https://stem.openhive.network/images/stemsocialsupport7.png'> </div>

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider <a href="https://hivesigner.com/sign/update-proposal-votes?proposal_ids=%5B91%5D&amp;approve=true">supporting our funding proposal</a>, <a href="https://hivesigner.com/sign/account_witness_vote?approve=1&witness=stem.witness">approving our witness</a> (@stem.witness) or delegating to the @steemstem account (for some ROI).

Please consider using the <a href='https://stem.openhive.network'>STEMsocial app</a> app and including @stemsocial as a beneficiary to get a stronger support.&nbsp;<br />&nbsp;<br />
properties (22)
authorsteemstem
permlinkre-mathowl-a-note-on-closing-figures-in-python-and-a-cute-cat-pic-20200512t074737867z
categoryhive-196387
json_metadata{"app":"stemsocial"}
created2020-05-12 07:47:39
last_update2020-05-12 07:47:39
depth1
children0
last_payout2020-05-19 07:47:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length777
author_reputation262,017,435,115,313
root_title"A note on closing figures in python and a cute cat pic"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,325,238
net_rshares0