1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

The Japanese translation of "A Whirlwind Tour of Python" - Appendix: Figure Code

Last updated at Posted at 2018-01-20

付録:図のコード

この節は、このレポートで現れる図を生成するために使われるコードを含みます。

In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
In [2]:
import os
if not os.path.exists('fig'):
    os.makedirs('fig')

Section 6: List Indexing

図はPythonのインデックスがいかに作用するかを可視化するのを支えます。

In [3]:
L = [2, 3, 5, 7, 11]

fig = plt.figure(figsize=(10, 4))
ax = fig.add_axes([0, 0, 1, 1], xticks=[], yticks=[], frameon=False,
                  aspect='equal')

for i in range(5):
    ax.add_patch(plt.Rectangle([i - 0.5, -0.5], 1, 1, fc='none', ec='black'))
    ax.text(i, -0.05, L[i], size=100,
            ha='center', va='center', family='monospace')
    
for i in range(6):
    ax.text(i - 0.5, 0.55, str(i), size=20,
            ha='center', va='bottom', family='monospace')
    
for i in range(5):
    ax.text(i - 0.5, -0.58, str(-5 + i), size=20,
            ha='center', va='top', family='monospace')
    
ax.axis([-0.7, 4.7, -0.7, 0.7]);

fig.savefig('fig/list-indexing.png');

ダウンロード (2).png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?