Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" 

2Simple plotting function as a template. 

3""" 

4import numpy 

5 

6 

7def plot_xy(data, label=None, markersize=4, color=None, ax=None, **kwargs): 

8 """ 

9 Plots a simple cloud of points :math:`(X_i, Y_i)`. 

10 

11 :param data: matrices, first column is X, second column i Y 

12 :param label: name of the curve 

13 :param marker_size: marker size 

14 :param color: color 

15 :param ax: existing axis 

16 :param kwargs: additional arguements for function 

17 `plot <https://matplotlib.org/3.1.0/api/_as_gen/ 

18 matplotlib.pyplot.plot.html>`_ 

19 :return: axis 

20 

21 One example of this simple graph: 

22 

23 .. plot:: 

24 

25 import numpy 

26 import matplotlib.pyplot as plt 

27 from td2a_plotting import plot_xy 

28 

29 fig, ax = plt.subplots(1, 1) 

30 data = numpy.random.rand(10, 2) 

31 plot_xy(data, ax=ax) 

32 plt.show() 

33 """ 

34 if not isinstance(data, numpy.ndarray): 

35 raise TypeError("data must be an array not {}".format(type(data))) 

36 if len(data.shape) != 2: 

37 raise ValueError( 

38 "data must be a matrix but shape is {}".format(data.shape)) 

39 if data.shape[1] != 2: 

40 raise ValueError("data must be a matrix with two columns shape is {}" 

41 "".format(data.shape)) 

42 if ax is None: 

43 import matplotlib.pyplot as plt 

44 ax = plt.gca() 

45 

46 ax.plot(data[:, 0], data[:, 1], '.', markersize=markersize, 

47 color=color, label=label, **kwargs) 

48 if label is not None: 

49 ax.legend() 

50 return ax