Теперь Кью работает в режиме чтения

Мы сохранили весь контент, но добавить что-то новое уже нельзя

Как изменить размер фигур, нарисованных с помощью matplotlib?

ПрограммированиеData science+3
Анонимный вопрос
Data Science
  · 2,6 K
Openstack DevOps and IBM/Informix Certified DBA . Phd in Math (Duality of spaces of...  · 4 июл 2022
Код ниже использует две опции для изменения размера фигуры ( » означает отступ - пробел )
  1. fig.set_figheight(4)  ; fig.set_figwidth(8) 
  2. fig.set_size_inches(12,6)
(.env) boris@boris-All-Series:~/FIGSIZE$ cat figureSize2.py
import matplotlib.pyplot as plt  
import numpy as np  
def power(x, y):
» » » » if(y == 0): return 1
» » » » elif (int(y % 2) == 0):
» » » » » » » » return (power(x, int(y / 2)) *
» » » » » » » » » » » » power(x, int(y / 2)))
» » » » else:
» » » » » » » » return (x * power(x, int(y / 2)) *
» » » » » » » » » » » » power(x, int(y / 2)))
x = np.arange(0, 10, 0.1)  
y = power(x,4)*np.sin(x)  
z = power(x,4)*np.cos(x)  
fig = plt.figure()  
fig.set_figheight(4)  
fig.set_figwidth(8)  
# Adds subplot on position 1  
ax = fig.add_subplot(121)  
# Adds subplot on position 2  
ax2 = fig.add_subplot(122)  
ax.plot(x, y)  
ax2.plot(x, z)  
fig = plt.figure()  
fig.set_size_inches(12,6)  
# Adds subplot on position 1  
ax = fig.add_subplot(121)  
# Adds subplot on position 2  
ax2 = fig.add_subplot(122)  
ax.plot(x, y)  
ax2.plot(x, z)  
plt.show()