Various previously introduced how to draw diagrams by matplotlib and pandas / ynakayama / items / 68eff3cb146181329b48) But I didn't mention the specific parameters. From this time, I will follow the drawing with matplotlib several times.
The matplotlib Figure object provides plotting functionality. The plt.figure () method draws a new window with nothing drawn. The add_subplot () method creates a subplot inside it.
import numpy as np
from pandas import *
from pylab import *
import matplotlib.pyplot as plt
from matplotlib import font_manager
from numpy.random import randn
#Required to use Japanese
fontprop = matplotlib.font_manager.FontProperties(fname="/usr/share/fonts/truetype/fonts-japanese-gothic.ttf")
#Draw a new window
fig = plt.figure()
#Add subplot
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,3)
plt.show()
plt.savefig("image.png ")
When you plot, matplotlib draws on the last of the figures and subplots you use.
ran = randn(50).cumsum()
#Black(k)Draw with the dashed line of
plt.plot(ran, 'k--')
plt.show()
plt.savefig("image2.png ")
You can draw on any subplot by explicitly calling the subplot instance method.
ax1.hist(rand(100), bins=20, color='k', alpha=0.3)
ax2.scatter(np.arange(30), np.arange(30) + 3 * randn(30))
plt.show()
plt.savefig("image3.png ")
Use the subplots_adjust method to adjust the space between subplots.
fig, axes = plt.subplots(2, 2, sharex=True, sharey=True)
for i in range(2):
for j in range(2):
axes[i, j].hist(randn(500), bins=50, color='k', alpha=0.5)
#Try to fill in the blanks between the subplots
plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0, hspace=0)
plt.show()
plt.savefig("image4.png ")
Introduction to data analysis with Python-Data processing using NumPy and pandas http://www.oreilly.co.jp/books/9784873116556/
Recommended Posts