/ Python And R Data science skills: 75 fig-size attribute save-fig and dpi

Sunday, 18 February 2018

75 fig-size attribute save-fig and dpi

https://vlrtraining.com/courses/python-data-science-beginner-tutorial 75 figsize attribute savefig and dpi
In [1]:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 5, 11)
y = x ** 2 
%matplotlib inline
In [35]:
fig = plt.figure()

ax = fig.add_axes([0,0,1,1])

ax.plot(x, y,"r")
#ax.plot(y, x,"g")
Out[35]:
[<matplotlib.lines.Line2D at 0xb11b5c0>]
In [37]:
fig = plt.figure(figsize=(7,4))

ax = fig.add_axes([0,0,1,1])

ax.plot(x, y,"r")
#ax.plot(y, x,"g")
Out[37]:
[<matplotlib.lines.Line2D at 0xb1cf3c8>]
In [38]:
fig = plt.figure(figsize=(7,2))

ax = fig.add_axes([0,0,1,1])

ax.plot(x, y,"r")
#ax.plot(y, x,"g")
Out[38]:
[<matplotlib.lines.Line2D at 0xb232dd8>]
In [39]:
fig, axes = plt.subplots()
axes.plot(x, y, 'r')
Out[39]:
[<matplotlib.lines.Line2D at 0xb1f3d30>]
In [40]:
fig, axes = plt.subplots(figsize=(12,3))
axes.plot(x, y, 'r')
Out[40]:
[<matplotlib.lines.Line2D at 0x9cc3828>]
In [41]:
fig, axes = plt.subplots(2,1,figsize=(12,3))
axes[0].plot(x, y, 'r')
axes[1].plot(x, y, 'r')
Out[41]:
[<matplotlib.lines.Line2D at 0x8b49400>]
In [42]:
fig, axes = plt.subplots(2,1,figsize=(12,3))
axes[0].plot(x, y, 'r')
axes[1].plot(x, y, 'r')

plt.tight_layout()
In [47]:
fig, axes = plt.subplots(2,1,figsize=(12,3),dpi=100)
axes[0].plot(x, y, 'r')
axes[1].plot(x, y, 'r')

plt.tight_layout()
In [48]:
fig
Out[48]:
In [49]:
fig.savefig("ram4.png")
In [50]:
fig.savefig("ram5.png",dpi=77)
In [51]:
fig.savefig("rame33a.pdf")

No comments:

Post a Comment