## 2020年5月26日火曜日

### 数学 - Python - 代数学 - 1次関数、2次関数 - 1次関数とそのグラフ - 傾き、切片

1. 第2象限を通るのは

$\left(1\right),\left(3\right),\left(4\right),\left(5\right)$

第3象限を通るのは

$\left(1\right),\left(2\right),\left(4\right),\left(6\right)$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, plot

print('5, 6.')
a, b, x = symbols('a, b, x')
f = a * x + b
g1 = f.subs({a: 1})
g2 = f.subs({a: -1})
h1 = f.subs({b: 1})
h2 = f.subs({b: -1})

p = plot(*[l.subs({c: n})
for l, c in [(g1, b), (h1, a), (g2, b), (h2, a)]
for n in range(-1, 2)],
(x, -5, 5),
ylim=(-5, 5),
legend=True,
show=False)

colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']

for o, color in zip(p, colors):
o.line_color = color

p.show()
p.save('sample5.png')

if __name__ == "__main__":
main()

% ./sample5.py
5, 6.
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/sympy/plotting/plot.py:1065: MatplotlibDeprecationWarning:
The set_smart_bounds function was deprecated in Matplotlib 3.2 and will be removed two minor releases later.
self.ax[i].spines['left'].set_smart_bounds(True)
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/sympy/plotting/plot.py:1066: MatplotlibDeprecationWarning:
The set_smart_bounds function was deprecated in Matplotlib 3.2 and will be removed two minor releases later.
self.ax[i].spines['bottom'].set_smart_bounds(False)

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
%