1

I am trying to make a data marker on a python plot that shows the x and y coordinates, preferably automatically if this is possible. Please keep in mind that I am new to python and do not have any experience using the marker functionality in matplotlib. I have FFT plots from .csv files that I am trying to compare to theoretical calculations, but I need a way of highlighting a specific point and dropping a marker that has the coordinate values similar to MATLAB. For reference, I am plotting an FFT of frequency intensity of a 100kHz sine wave with an amplitude of 1V, so I am trying to show that the spike at 100kHz is close to the calculated value of 3.98dBm in a 50ohm environment. Here is some of the data from my csv file around the point of interest (The third column is of no interest):

9.991250000000E+04  -8.399371E+01   0.000000E+00
9.992500000000E+04  -8.108232E+01   0.000000E+00
9.993750000000E+04  -7.181630E+01   0.000000E+00
9.995000000000E+04  -7.190387E+01   0.000000E+00
9.996250000000E+04  -7.961070E+01   0.000000E+00
9.997500000000E+04  -8.090104E+01   0.000000E+00
9.998750000000E+04  -1.479405E+01   0.000000E+00
1.000000000000E+05  3.740311E+00    0.000000E+00
1.000125000000E+05  -6.665535E-01   0.000000E+00
1.000250000000E+05  -7.868803E+01   0.000000E+00
1.000375000000E+05  -8.149953E+01   0.000000E+00
1.000500000000E+05  -7.948487E+01   0.000000E+00
1.000625000000E+05  -7.436191E+01   0.000000E+00
1.000750000000E+05  -8.068216E+01   0.000000E+00
1.000875000000E+05  -7.998886E+01   0.000000E+00
1.001000000000E+05  -8.316663E+01   0.000000E+00

Here is how I am extracting the data

Frequency = data[:,0]
Intensity = data[:,1]

title("Frequency Intensity")
xlabel("Frequency [Hz]")
ylabel("Intensity [dBm]")
plot(Frequency, Intensity)
grid();

Edit: I would like my plot to look something like this where x shows the frequency and y shows the intensity in dBm. I simply want the marker I place to show the x,y coordinates on the plot.

FFT plot desired marker

4
  • Could you mock (just draw in the image editor) the picture you are trying to get? I'm actually not sure I'm understand correctly what "make a data marker" mean. You also probably can check annotate. Commented Jan 29, 2017 at 20:59
  • @IlyaV.Schurov I have made an edit above in the description of my question under the "Edit:" section. Commented Jan 29, 2017 at 21:05
  • Can you clarify for me -- Is your question about (a) how to calculate the coordinates that your x, y should be at or do you already know these coordinates and your question is simply (b) how to place a marker at those coordinates? Commented Jan 29, 2017 at 22:32
  • @AlAvery my question wat how to place a marker with text at those coordinates. The answer posted below is exactly what I am looking for! Commented Jan 29, 2017 at 22:42

2 Answers 2

1

Create a pd.Series from data

s = pd.DataFrame({
        'Frequency [Hz]': data[:, 0],
        'Intensity [dBm]': data[:, 1]
    }).set_index('Frequency [Hz]')['Intensity [dBm]']

Then plot with annotate

ax = s.plot(title='Frequency Intensity')
ax.set_ylabel(s.name)
point = (s.index[7], s.values[7])
ax.annotate('Marker', xy=point, xytext=(0.1, 0.95), textcoords='axes fraction',
            arrowprops=dict(facecolor='black', shrink=0.05),
            )

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

You probably want something like this:

import numpy as np
import matplotlib.pyplot as plt

# assuming we are in Jupyter
%matplotlib inline

frequency = np.array(
    [  99912.5,   99925. ,   99937.5,   99950. ,   99962.5,   99975. ,
       99987.5,  100000. ,  100012.5,  100025. ,  100037.5,  100050. ,
       100062.5,  100075. ,  100087.5,  100100. ])
intensity = np.array(
    [-83.99371  , -81.08232  , -71.8163   , -71.90387  , -79.6107   ,
     -80.90104  , -14.79405  ,   3.740311 ,  -0.6665535, -78.68803  ,
     -81.49953  , -79.48487  , -74.36191  , -80.68216  , -79.98886  ,
     -83.16663  ])

plt.title("Frequency Intensity")
plt.xlabel("Frequency [Hz]")
plt.ylabel("Intensity [dBm]")
plt.plot(frequency, intensity)
x = frequency[7]
y = intensity[7]
plt.plot([x], [y], 'v', color='red', ms=10)
plt.text(x, y, "({:0.2f}, {:0.2f})".format(x, y))
plt.grid()

picture with marker

1 Comment

@nichollsg, you're welcome. If the answer solves your problem, you can accept an answer by clicking on checkmark to the left of it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.