Programming/python(파이썬)
matplotlib
구차니
2023. 10. 4. 23:27
gnuplot을 래핑해서 만든건줄 알았는데 독립된 건가?
[링크 : https://matplotlib.org/stable/tutorials/pyplot.html]
500.000 points scatterplot gnuplot: 5.171 s matplotlib: 230.693 s |
[링크 : https://stackoverflow.com/questions/911655/gnuplot-vs-matplotlib]
2차축 추가. y축에 대해서 주로 넣지 x 축에 넣는건 먼가 신선하네
import datetime import matplotlib.pyplot as plt import numpy as np import matplotlib.dates as mdates from matplotlib.ticker import AutoMinorLocator fig, ax = plt.subplots(layout='constrained') x = np.arange(0, 360, 1) y = np.sin(2 * x * np.pi / 180) ax.plot(x, y) ax.set_xlabel('angle [degrees]') ax.set_ylabel('signal') ax.set_title('Sine wave') def deg2rad(x): return x * np.pi / 180 def rad2deg(x): return x * 180 / np.pi secax = ax.secondary_xaxis('top', functions=(deg2rad, rad2deg)) secax.set_xlabel('angle [rad]') plt.show() |
[링크 : https://matplotlib.org/stable/gallery/subplots_axes_and_figures/secondary_axis.html]
특이하게 배열로 된 값이 들어가는게 아닌, 함수를 통해서 1차축에 대해서 계산해서 2차축을 쓰는 듯?
Axes.secondary_xaxis(location, *, functions=None, **kwargs) Axes.secondary_yaxis(location, *, functions=None, **kwargs) functions2-tuple of func, or Transform with an inverse If a 2-tuple of functions, the user specifies the transform function and its inverse. i.e. functions=(lambda x: 2 / x, lambda x: 2 / x) would be an reciprocal transform with a factor of 2. Both functions must accept numpy arrays as input. The user can also directly supply a subclass of transforms.Transform so long as it has an inverse. See Secondary Axis for examples of making these conversions. |