<jupyter_start><jupyter_text>Learn Matplotlib Basic<jupyter_code># show in notebook, and not block, # don't need call plt.show()
%matplotlib inline
import numpy as np
import matplotlib.pylab as plt

# http://pandas.pydata.org/pandas-docs/version/0.13/visualization.html

# datetime timeseries display
# https://blog.csdn.net/fortware/article/details/51934814
# https://matplotlib.org/gallery/api/date.html
# figure and show
fig = plt.figure(figsize=(2, 2))
ax = fig.add_subplot(111)

# set x/y scale range
ax.set_xlim([0,4])
ax.set_ylim([0,8])

# grid
ax.grid(True)
# 设置子图之间的间距
plt.tight_layout(pad = 3, h_pad=0.5, w_pad=0.5)

# 为了防止Jupyter notebook有时候Double plot, 在plot函数的后面加分号;
plt.plot([1,2,3,4,5]);
fig = plt.figure(figsize=(1, 1))
ax = fig.add_subplot(111)
ax.set_title('axis off')
ax.axis('off')
ax.plot([1,2,3,4,5])
fig = plt.figure(figsize=(3, 3))
ax = fig.add_subplot(111)
# not my disired result
# ax.set_visible(Flase)

# set axis label
ax.set_xlabel('X')
ax.set_ylabel('Y')

ax.plot(np.random.randn(1000).cumsum(), label='line0')

# set axis scale and scale label
ax.set_xticks(range(0,1000,100))
ax.set_xticklabels(list('abcdefghij'))
# ax.set_xticklabels([])
# get current axis
ax = plt.gca()
# y axis visible
ax.axes.get_yaxis().set_visible(False)
# x axis visible
ax.axes.get_xaxis().set_visible(False)
# another set about axis and ticks
# plt.xticks([]) and plt.yticks([])
# plt.xlim([]) and plt.ylim([])
# plt.xlabel() and plt.ylabel()
# plt.axis('off')
# plt.tile()
# hide the spines (轴,脊骨)
fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(10, 2))
# clear the ticks on axis of x,y 
axes[0].set_xticks([])
axes[0].set_yticks([])

axes[1].xaxis.set_ticks_position('top')
axes[1].spines['bottom'].set_position(('data', 0.5))
axes[1].yaxis.set_ticks_position('right')
axes[1].spines['left'].set_position(('data', 0.5))

axes[2].spines['right'].set_color('none')
axes[2].spines['top'].set_color('none')
axes[2].spines['bottom'].set_position(('data', 0.5))

axes[2].set_yticklabels(list('abcdef'))
axes[2].set_xticks([])
# set the around size between subplots
plt.subplots_adjust(wspace=0.5, hspace=0)
fig.set_figheight(10)
fig.set_figwidth(10)<jupyter_output><empty_output><jupyter_text>在Cell中复用<jupyter_code>fig, ax = plt.subplots(1, 1, figsize=(4,4))
ax.scatter([1],[1])
# 另一个cell
ax.scatter([2],[2])
fig<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19124521886952825, 'fraction_numerical': 0.04037399065023375, 'mean_word_length': 6.40251572327044, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '476579', 'license': 'MIT', 'n_tokens_mistral': 1065, 'n_tokens_neox': 1023, 'n_words': 169, 'path': 'python/learn/matplot/base_learn_matplotlib.ipynb', 'repo_name': 'qrsforever/workspace', 'size': '2353'}