/usr/lib/python2.7/dist-packages/aplpy/layers.py is in python-aplpy 1.1.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | from __future__ import absolute_import, print_function, division
from matplotlib.contour import ContourSet
from matplotlib.collections import RegularPolyCollection, \
PatchCollection, CircleCollection, LineCollection
from .regions import ArtistCollection
from .decorators import auto_refresh
class Layers(object):
def __init__(self):
pass
def _layer_type(self, layer):
if isinstance(self._layers[layer], ContourSet):
return 'contour'
elif isinstance(self._layers[layer], RegularPolyCollection):
return 'collection'
elif isinstance(self._layers[layer], PatchCollection):
return 'collection'
elif isinstance(self._layers[layer], CircleCollection):
return 'collection'
elif isinstance(self._layers[layer], LineCollection):
return 'collection'
elif isinstance(self._layers[layer], ArtistCollection):
return 'collection'
elif hasattr(self._layers[layer], 'remove') and hasattr(self._layers[layer], 'get_visible') and hasattr(self._layers[layer], 'set_visible'):
return 'collection'
else:
raise Exception("Unknown layer type: " + \
str(type(self._layers[layer])))
def _initialize_layers(self):
self._layers = {}
self._contour_counter = 0
self._vector_counter = 0
self._scatter_counter = 0
self._circle_counter = 0
self._ellipse_counter = 0
self._rectangle_counter = 0
self._linelist_counter = 0
self._region_counter = 0
self._label_counter = 0
self._poly_counter = 0
def list_layers(self):
'''
Print a list of layers to standard output.
'''
layers_list = []
for layer in self._layers:
layer_type = self._layer_type(layer)
if layer_type == 'contour':
visible = self._layers[layer].collections[0].get_visible()
elif layer_type == 'collection':
visible = self._layers[layer].get_visible()
layers_list.append({'name': layer, 'visible': visible})
n_layers = len(layers_list)
if n_layers == 0:
print("\n There are no layers in this figure")
else:
if n_layers == 1:
print("\n There is one layer in this figure:\n")
else:
print("\n There are " + str(n_layers) + \
" layers in this figure:\n")
for layer in layers_list:
if layer['visible']:
print(" -> " + layer['name'])
else:
print(" -> " + layer['name'] + " (hidden)")
@auto_refresh
def remove_layer(self, layer, raise_exception=True):
'''
Remove a layer.
Parameters
----------
layer : str
The name of the layer to remove
'''
if layer in self._layers:
layer_type = self._layer_type(layer)
if layer_type == 'contour':
for contour in self._layers[layer].collections:
contour.remove()
self._layers.pop(layer)
elif layer_type == 'collection':
self._layers[layer].remove()
self._layers.pop(layer)
if (layer + '_txt') in self._layers:
self._layers[layer + '_txt'].remove()
self._layers.pop(layer + '_txt')
else:
if raise_exception:
raise Exception("Layer " + layer + " does not exist")
@auto_refresh
def hide_layer(self, layer, raise_exception=True):
'''
Hide a layer.
This differs from remove_layer in that if a layer is hidden
it can be shown again using show_layer.
Parameters
----------
layer : str
The name of the layer to hide
'''
if layer in self._layers:
layer_type = self._layer_type(layer)
if layer_type == 'contour':
for contour in self._layers[layer].collections:
contour.set_visible(False)
elif layer_type == 'collection':
self._layers[layer].set_visible(False)
else:
if raise_exception:
raise Exception("Layer " + layer + " does not exist")
@auto_refresh
def show_layer(self, layer, raise_exception=True):
'''
Show a layer.
This shows a layer previously hidden with hide_layer
Parameters
----------
layer : str
The name of the layer to show
'''
if layer in self._layers:
layer_type = self._layer_type(layer)
if layer_type == 'contour':
for contour in self._layers[layer].collections:
contour.set_visible(True)
elif layer_type == 'collection':
self._layers[layer].set_visible(True)
else:
if raise_exception:
raise Exception("Layer " + layer + " does not exist")
def get_layer(self, layer, raise_exception=True):
'''
Return a layer object.
Parameters
----------
layer : str
The name of the layer to return
'''
if layer in self._layers:
return self._layers[layer]
else:
if raise_exception:
raise Exception("Layer " + layer + " does not exist")
|