0
$\begingroup$

I am trying to create a dotplot in the same format as the one below Example of Graph I want to Create

but my .dat file gives me a list of the data with each datapoint contained in a list Output from .dat file

When I use the ListPlot[data] function, it gives me an incorrect plot, I am having trouble fixing the x-axis. How do I get it to show each data point one at a time from 0 to 512

Plot from ListPlot

$\endgroup$
3
  • $\begingroup$ Are you saying that the x-value should be just the index mod 512? $\endgroup$
    – lericr
    Dec 19, 2022 at 20:57
  • $\begingroup$ Yeah, so like the first value would be (1, 0.7159771270002675), second value would be (2,0.3062832599074649) till the final value. I don't know how to get the x-axis to increment by 1 $\endgroup$
    – Prith
    Dec 19, 2022 at 21:02
  • 1
    $\begingroup$ ListPlot[testData // Flatten] $\endgroup$
    – Bob Hanlon
    Dec 19, 2022 at 21:55

1 Answer 1

1
$\begingroup$

Maybe something like this:

testData = Array[{RandomReal[{-1, 1}]} &, 2000];
indexedData = MapIndexed[Join[Mod[#2, 512], #1] &, testData];
ListPlot[indexedData]

enter image description here

Or if you want unique x values up to total number of datapoints:

testData = Array[{RandomReal[{-1, 1}]} &, 512];
indexedData = MapIndexed[Join[#2, #1] &, testData];
ListPlot[indexedData]

enter image description here

You could also just create the list of indices/x-values independently:

testData = Array[{RandomReal[{-1, 1}]} &, 512];
indexedData = Transpose[{Range@Length@testData, Flatten@testData}];
ListPlot[indexedData]
$\endgroup$
4
  • $\begingroup$ where do I input the .dat file in this code? I'm very sorry but I don't understand how to get the specific data I need to use into the testData variable. $\endgroup$
    – Prith
    Dec 19, 2022 at 21:09
  • $\begingroup$ I have 512 points of data that I want to plot in order starting from the first piece of data in the file to the last piece of data in the file. All I have is the y-axis value of the data and the x-axis value just needs to be 1 to 512 with 1 being the first data value, 2 being the second data value, 3 being the third data value. and so on. $\endgroup$
    – Prith
    Dec 19, 2022 at 21:11
  • $\begingroup$ I thought you had already executed data = Import[...]. Just substitute data for testData. If that doesn't work, then we'd need to see what the actual result of the Import was, and maybe the actual structure of the .dat file. $\endgroup$
    – lericr
    Dec 19, 2022 at 21:14
  • $\begingroup$ Thank you very much, this worked as intended. $\endgroup$
    – Prith
    Dec 19, 2022 at 21:15

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.