本文整理汇总了Python中matplotlib.collections.PatchCollection.set_offset_position方法的典型用法代码示例。如果您正苦于以下问题:Python PatchCollection.set_offset_position方法的具体用法?Python PatchCollection.set_offset_position怎么用?Python PatchCollection.set_offset_position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.collections.PatchCollection
的用法示例。
在下文中一共展示了PatchCollection.set_offset_position方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from matplotlib.collections import PatchCollection [as 别名]
# 或者: from matplotlib.collections.PatchCollection import set_offset_position [as 别名]
def render(self, patch_size=0.5, alpha=1.0, x_offset=100):
'''Draws the legend graphic and saves it to a file.'''
n = len(self.colors)
s = patch_size
# This offset is transformed to "data" coordinates (inches)
left_offset = (-s * 1.5) - (x_offset / self.dpi)
# Create grid to plot the artists
grid = np.concatenate((
np.zeros(n).reshape(n, 1),
np.arange(-n, 1)[1:].reshape(n, 1)
), axis=1)
plt.text(left_offset, 1.1, 'Legend', family='sans-serif',
size=14, weight='bold', color='#ffffff')
patches = []
for i in range(n):
# Add a rectangle
rect = mpatches.Rectangle(grid[i] - [0, 0], s, s, ec='none')
patches.append(rect)
self.__label__(grid[i], self.labels[i], x_offset)
collection = PatchCollection(patches, alpha=alpha)
# Space the patches and the text labels
collection.set_offset_position('data')
collection.set_offsets(np.array([
[left_offset, 0]
]))
collection.set_facecolors(self.colors)
#collection.set_edgecolor('#ffffff') # Draw color for box outlines
self.axis.add_collection(collection)
plt.axis('equal')
plt.axis('off')
plt.savefig(self.file_path, facecolor=self.bg_color, dpi=self.dpi,
pad_inches=0)
return self.file_path