Skip to content

Instantly share code, notes, and snippets.

@falgon
Created April 15, 2018 14:10
Show Gist options
  • Save falgon/84614f9f8be752f8ada1f7d4379d00b1 to your computer and use it in GitHub Desktop.
Save falgon/84614f9f8be752f8ada1f7d4379d00b1 to your computer and use it in GitHub Desktop.
# -*- coding:utf-8 -*-
#!/usr/bin/env python
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import warnings
from matplotlib.font_manager import FontProperties
h, w = -2, 2
density = 1024
def non_parametric():
warnings.simplefilter("ignore") # Python warns that it is `invalid value encountered in sqrt`, but that is the purpose itself.
x = np.linspace(h, w, density)
y = np.sqrt(x**3+x**2)
return u'非パラメトリック', x, y
def parametric():
x = []
y = []
for t in np.linspace(h, w, density):
x.append(t**2-1)
y.append(t**3-t)
return u'パラメトリック', x, y
def setting(ax):
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.axvline(0, color = 'b', lw = 1.1)
ax.axhline(0, color = 'b', lw = 1.1)
ax.grid(color = 'gray')
if __name__ == '__main__':
title, x, y = parametric()
# Here, I use the font that is `IPA ゴシック (Ver.003.03)` to display Japanese(https://ipafont.ipa.go.jp/old/ipafont/download.html#en).
fp = FontProperties(fname = 'ipag.ttf', size = 14)
fig, (axL, axR) = plt.subplots(ncols = 2, figsize = (10, 4), sharex = 'all', sharey = 'all')
title0, x0, y0 = non_parametric()
axL.plot(x0, y0)
axL.set_title(title0, loc = 'center', fontproperties = fp)
axL.set_xlim(h, w)
axL.set_ylim(h, w)
setting(axL)
title1, x1, y1 = parametric()
axR.plot(x1, y1)
axR.set_title(title1, loc = 'center', fontproperties = fp)
setting(axR)
plt.savefig('curves0.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment