Answers for "plt line"

1

python matplotlib how to graph point on line

import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xlim(0,10)
ax.set_ylim(0,10)

# draw lines
xmin = 1
xmax = 9
y = 5
height = 1
plt.hlines(y, xmin, xmax)
plt.vlines(xmin, y - height / 2., y + height / 2.)
plt.vlines(xmax, y - height / 2., y + height / 2.)
average = (xmax+xmin)/2

# draw a point on the line
px = 5 
plt.plot(px,y, 'ro', ms = 15, mfc = 'r')

# add an arrow
plt.annotate('Point', (px,y), xytext = (px+0.35, y+0.5), 
horizontalalignment='right')

# add numbers
plt.text(xmin - 0.1, y, 'Left', horizontalalignment='right')
plt.text(xmax + 0.1, y, 'Right', horizontalalignment='left')

plt.axis('off')
plt.show()
Posted by: Guest on August-06-2020
0

lineplot in plt

CHAPTER

                                                                                                           FOUR

                                                          FREQUENTLY ASKED QUESTIONS

A list of common questions.

4.1 How can I fit multi-dimensional data?

The fitting routines accept data arrays that are 1 dimensional and double precision. So you need to convert the data
and model (or the value returned by the objective function) to be one dimensional. A simple way to do this is to use
numpy’s numpy.ndarray.flatten(), for example:
def residual(params, x, data=None):
    ....
    resid = calculate_multidim_residual()
    return resid.flatten()

4.2 How can I fit multiple data sets?

As above, the fitting routines accept data arrays that are 1 dimensional and double precision. So you need to convert
the sets of data and models (or the value returned by the objective function) to be one dimensional. A simple way to
do this is to use numpy’s numpy.concatenate(). As an example, here is a residual function to simultaneously
fit two lines to two different arrays. As a bonus, the two lines share the ‘offset’ parameter:
      def fit_function(params, x=None, dat1=None, dat2=None): 
      		model1 = params[’offset’].value + x * params[’slope1’].value 
        	model2 = params[’offset’].value + x * params[’slope2’].value
           	resid1 = dat1 - model1 
            resid2 = dat2 - model2 
            return numpy.concatenate((resid1, resid2))

4.3 How can I fit complex data?

As with working with multidimensional data, you need to convert your data and model (or the value returned by the
objective function) to be double precision floating point numbers. One way to do this would be to use a function like
this:
def realimag(array):
    return np.array([(x.real, x.imag) for x in array]).flatten()

to convert the complex array into an array of alternating real and imaginary values. You can then use this function on
the result returned by your objective function:

                                                                                                                   13
Posted by: Guest on October-31-2021

Python Answers by Framework

Browse Popular Code Answers by Language