@SnoopJeDi/

AngryMedicalConditionals

Python

No description

fork
loading
Files
  • main.py
  • out_clipped.png
  • out.png

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.36017233904055557","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"IiIiCkFkZGluZyBhIGdsb2JhbCBsZWdlbmQgdG8gYSBtYXRwbG90bGliIGZpZ3VyZSB3aXRoIHN1YnBsb3RzCkJhc2VkIG9uIGEgcXVlc3Rpb24gaW4gI3B5dGhvbiBvbiBmcmVlbm9kZSwgTm92IDcsIDIwMTgKIiIiCmltcG9ydCBtYXRwbG90bGliCm1hdHBsb3RsaWIudXNlKCdhZ2cnKQpmcm9tIG1hdHBsb3RsaWIgaW1wb3J0IHB5cGxvdCBhcyBwbHQKaW1wb3J0IG51bXB5IGFzIG5wCgphcnIgPSBucC5hcnJheShbMSwyLDNdKQpmaWcgPSBwbHQuZmlndXJlKGZpZ3NpemU9KDIqNCwgNCkpCnBsdC5zdWJwbG90KDEyMSkKbDEgPSBwbHQucGxvdChhcnIsIGFycioqMiwgbGFiZWw9J2ZvbycpCmwyID0gcGx0LnBsb3QoYXJyLCBhcnIqKjMsIGxhYmVsPSdiYXInKQoKcGx0LnN1YnBsb3QoMTIyKQpsMyA9IHBsdC5wbG90KGFyciwgYXJyKioyLCAnay0tJywgbGFiZWw9J2JpbicpCmw0ID0gcGx0LnBsb3QoYXJyLCBhcnIqKjMsICdycycsIG1mYz0nbm9uZScpICAjIG5vIGxhYmVsIQoKbGduZCA9IGZpZy5sZWdlbmQoYmJveF90b19hbmNob3I9KDEuMSwgMS4wKSkgIyB1bmZvcnR1bmF0ZWx5LCBsb2M9J2Jlc3QnIGRvZXNuJ3Qgd29yayB2ZXJ5IHdlbGwgaGVyZQpmaWcudGlnaHRfbGF5b3V0KCkKCiMgdGhlIGxlZ2VuZCBpcyBub3QgYWNjb3VudGVkIGZvciBieSBkZWZhdWx0IHdoZW4gY2FsbGluZyBzYXZlZmlnKCksIHNvIHdlIG5lZWQgdG8gZ2l2ZSBzb21lIGhpbnRzCiMgTi5CLiB0aGF0IGBiYm94X2V4dHJhX2FydGlzdHNgIGlzIG5vdCBzdHJpY3RseSBuZWNlc3NhcnkgaGVyZSB0byBnZXQgdGhlIHJpZ2h0IG91dHB1dCwgYnV0IGl0J3MgYSBnb29kIGlkZWEhCmZpZy5zYXZlZmlnKCdvdXRfY2xpcHBlZC5wbmcnKQpmaWcuc2F2ZWZpZygnb3V0LnBuZycsIGJib3hfZXh0cmFfYXJ0aXN0cz1bbGduZF0sIGJib3hfaW5jaGVzPSd0aWdodCcpICA="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""
Adding a global legend to a matplotlib figure with subplots
Based on a question in #python on freenode, Nov 7, 2018
"""
import matplotlib
matplotlib.use('agg')
from matplotlib import pyplot as plt
import numpy as np

arr = np.array([1,2,3])
fig = plt.figure(figsize=(2*4, 4))
plt.subplot(121)
l1 = plt.plot(arr, arr**2, label='foo')
l2 = plt.plot(arr, arr**3, label='bar')

plt.subplot(122)
l3 = plt.plot(arr, arr**2, 'k--', label='bin')
l4 = plt.plot(arr, arr**3, 'rs', mfc='none')  # no label!

lgnd = fig.legend(bbox_to_anchor=(1.1, 1.0)) # unfortunately, loc='best' doesn't work very well here
fig.tight_layout()

# the legend is not accounted for by default when calling savefig(), so we need to give some hints
# N.B. that `bbox_extra_artists` is not strictly necessary here to get the right output, but it's a good idea!
fig.savefig('out_clipped.png')
fig.savefig('out.png', bbox_extra_artists=[lgnd], bbox_inches='tight')