SciencePlots で学会フォーマットの作図 (Matplotlib)

モジュールのインポート

import numpy as np
import matplotlib.pyplot as plt

SciencePlots

SciencePlotsについては,
https://pypi.org/project/SciencePlots/
参照.インポートは,次のとおり.
import scienceplots
#Warning : As of version 2.0.0, you need to add import scienceplots before setting the style (plt.style.use('science')).
plt.style.use(['science', 'notebook'])
計算例として,
x = np.linspace(1,10,100) # 等間隔の1次元配列(0から10)
y = 1/x**2 * np.sin(x)
微分は,
https://numpy.org/doc/stable/reference/generated/numpy.gradient.html
dydx = np.gradient(y, x)
また,積分は,簡単のため,累積和
https://numpy.org/doc/stable/reference/generated/numpy.cumsum.html
を使って近似すると,
y_int = np.cumsum(y) * (x[1]-x[0]) # 累積和
y_int
array([0.07649736, 0.1442579 , 0.20448433, 0.25813208, 0.30597568,
       0.34865441, 0.38670447, 0.42058214, 0.45068077, 0.47734356,
       0.50087314, 0.52153899, 0.53958321, 0.55522502, 0.56866433,
       0.58008456, 0.58965497, 0.59753247, 0.60386313, 0.6087834 ,
       0.61242109, 0.61489623, 0.61632168, 0.61680376, 0.61644265,
       0.61533281, 0.6135633 , 0.61121804, 0.60837603, 0.60511157,
       0.60149442, 0.59758994, 0.59345921, 0.5891592 , 0.58474281,
       0.58025901, 0.57575297, 0.57126608, 0.56683611, 0.56249727,
       0.55828035, 0.55421275, 0.55031866, 0.54661911, 0.54313211,
       0.53987276, 0.53685334, 0.53408347, 0.53157023, 0.52931824,
       0.52732988, 0.52560532, 0.52414276, 0.52293849, 0.52198708,
       0.52128148, 0.52081322, 0.52057249, 0.52054833, 0.52072874,
       0.52110084, 0.52165099, 0.52236495, 0.52322799, 0.524225  ,
       0.52534068, 0.52655958, 0.52786626, 0.52924541, 0.5306819 ,
       0.53216092, 0.53366807, 0.53518942, 0.53671161, 0.5382219 ,
       0.53970824, 0.54115933, 0.54256466, 0.54391458, 0.54520028,
       0.54641385, 0.54754831, 0.54859759, 0.54955655, 0.55042099,
       0.55118763, 0.5518541 , 0.55241892, 0.55288145, 0.55324192,
       0.55350134, 0.55366148, 0.55372484, 0.55369457, 0.55357446,
       0.55336886, 0.55308264, 0.55272113, 0.55229005, 0.55179549])
fig = plt.figure()
plt.plot(x,y, label=r"$y=f(x)$")
plt.plot(x,dydx, label=r"$dy/dx$")
plt.plot(x,y_int, label=r"$\int y dx$")
plt.legend(ncol=1, loc='upper right', fancybox=False, frameon = True)
fig.savefig("scienceplots_ex1.pdf")