前提・実現したいこと
ある実験を行い、xとyの二つのパラメータを変化させて、zを測定しました。
その後、pythonを用いて、画像のような図を作成しました。
xが横軸に、yが縦軸に対応しています。色の変化がzに対応しています。
ここから、zをxで微分して、そのグラフを作成したいのですが、うまくいきません。
発生している問題・エラーメッセージ
エラーメッセージとして、次の文章が表示されます。 ValueError Traceback (most recent call last) <ipython-input-4-67aedc53eb19> in <module>() 13 y = numerical_diff(f,x) 14 ---> 15 plt.plot(x, y) ~\Anaconda3\envs\Test1\lib\site-packages\matplotlib\pyplot.py in plot(*args, **kwargs) 3356 mplDeprecation) 3357 try: -> 3358 ret = ax.plot(*args, **kwargs) 3359 finally: 3360 ax._hold = washold ~\Anaconda3\envs\Test1\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs) 1853 "the Matplotlib list!)" % (label_namer, func.__name__), 1854 RuntimeWarning, stacklevel=2) -> 1855 return func(ax, *args, **kwargs) 1856 1857 inner.__doc__ = _add_data_doc(inner.__doc__, ~\Anaconda3\envs\Test1\lib\site-packages\matplotlib\axes\_axes.py in plot(self, *args, **kwargs) 1525 kwargs = cbook.normalize_kwargs(kwargs, _alias_map) 1526 -> 1527 for line in self._get_lines(*args, **kwargs): 1528 self.add_line(line) 1529 lines.append(line) ~\Anaconda3\envs\Test1\lib\site-packages\matplotlib\axes\_base.py in _grab_next_args(self, *args, **kwargs) 404 this += args[0], 405 args = args[1:] --> 406 for seg in self._plot_args(this, kwargs): 407 yield seg 408 ~\Anaconda3\envs\Test1\lib\site-packages\matplotlib\axes\_base.py in _plot_args(self, tup, kwargs) 381 x, y = index_of(tup[-1]) 382 --> 383 x, y = self._xy_from_xy(x, y) 384 385 if self.command == 'plot': ~\Anaconda3\envs\Test1\lib\site-packages\matplotlib\axes\_base.py in _xy_from_xy(self, x, y) 240 if x.shape[0] != y.shape[0]: 241 raise ValueError("x and y must have same first dimension, but " --> 242 "have shapes {} and {}".format(x.shape, y.shape)) 243 if x.ndim > 2 or y.ndim > 2: 244 raise ValueError("x and y can be no greater than 2-D, but have " ValueError: x and y must have same first dimension, but have shapes (1001,) and (17, 1001
該当のソースコード
``python
以下を行ったところ、エラーが出ました。
import numpy as np import matplotlib.pyplot as plt def numerical_diff(f,x): h = 1e-4 return (f(x+h) - f(x-h)) / (2*h) def f(x): return zdata x = xdata y = numerical_diff(f,x) plt.plot(x, y)
### 試したこと ここに問題に対して試したことを記載してください。 ### 補足情報(FW/ツールのバージョンなど) ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/09 09:31 編集
2018/08/09 12:49
2018/08/09 14:33