matplotlib 常用绘图
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
plt.rcParams['font.sans-serif'] = ['Arial Unicode MS']
fig, axs = plt.subplots(2, 2)
ax1 = axs[0][0]
ax2 = axs[0][1]
ax3 = axs[1][0]
ax4 = axs[1][1]
data = np.random.randn(10).cumsum()
ax1.plot(data, 'r--.')
ax2.plot(data, 'bo:', drawstyle='steps-mid', label='steps')
ax2.plot(data, 'r-', drawstyle='default', label='default')
ax2.legend(loc='best')
ax2.set_title('老标题党了')
ax3.plot(data)
ax3.set_xticks([0, 3, 6, 8])
ax3.set_xticklabels(['a', 'b', 'c', 'd'], rotation=30, fontsize='small')
ax3.set_yticks([-5, 5])
ax3.set_yticklabels(['y1', 'y2'], rotation=30, fontsize='small')
ax3.set_xlabel('xlabel')
ax3.set_ylabel('ylabel')
ax4.plot(data)
ax4.annotate('an1',
(2, data[2]),
arrowprops=dict(facecolor='red', headwidth=4, width=2, headlength=4))
ax4.annotate('an2',
(6, data[6]),
arrowprops=dict(facecolor='red', headwidth=4, width=2, headlength=4))
fig.savefig('mpt.png', dpi=400, bbox_inches='tight')
from io import BytesIO
buffer = BytesIO()
plt.savefig(buffer)
plot_data = buffer.getvalue()
print(plot_data)