0
$\begingroup$

This is complete mystery for me, but I am unable to plot the following data... I have two lists, that I want to ListPlot. The data is created in the following way (I edited the code for more clarity):

xx = Table[i, {i, 1.485, 1.5, .001}];
yy = Table[0, {i, Length[xx]}];

Then, I run a For on all the elements of yy to change their value. In the end, I get the following list:

yy = {2.2005*10^(-3),2.34527*10^(-3),2.50062*10^(-3),2.66517*10^(-3),2.83694*10^(-3),3.01328*10^(-3),3.19072*10^(-3),3.36471*10^(-3),3.52911*10^(-3),3.6752*10^(-3),3.7894*10^(-3),3.84831*10^(-3),3.80618*10^(-3),3.55756*10^(-3),2.79023*10^(-3),0.}

The thing is, when I try to

ListPlot[Transpose[{xx,yy}]

it does not work. I have to manually copy (copy as plain text) the generated list in place of yy, and then it works.

What's wrong with my yy? If needed I will copy the code that I use to change that list, but it is quite long... So if anybody knows that this kind of behavior is typical of something, please let me know.

Edited: xx and yy have the same length, sorry about that.

Also, when I try

ListPlot[Transpose[{xx,xx}]]

I do get a (obviously linear) plot, which means that everything is fine with xx, but whenever I try to add yy somewhere, MMA returns an empty plot.

Edit 2: as requested, here is the output of Transpose[{xx,yy}]:

{{1.485,2.2005*10^(-3)},{1.486,2.34527*10^(-3)},{1.487,2.50062*10^(-3)},{1.488,2.66517*10^(-3)},{1.489,2.83694*10^(-3)},{1.49,3.01328*10^(-3)},{1.491,3.19072*10^(-3)},{1.492,3.36471*10^(-3)},{1.493,3.52911*10^(-3)},{1.494,3.6752*10^(-3)},{1.495,3.7894*10^(-3)},{1.496,3.84831*10^(-3)},{1.497,3.80618*10^(-3)},{1.498,3.55756*10^(-3)},{1.499,2.79023*10^(-3)},{1.5,0.}}

and a screenshot of it as well (just in case):

Screenshot of xx and yy

Edit 3: I forgot the FullForm. Here we go, and I guess I see that the problem comes from there...

List[List[1.485`,ScientificForm[0.002200504961592269`]],List[1.486`,ScientificForm[0.002345269356606834`]],List[1.487`,ScientificForm[0.0025006194693353036`]],List[1.488`,ScientificForm[0.0026651682379572796`]],List[1.489`,ScientificForm[0.002836940677699209`]],List[1.49`,ScientificForm[0.0030132826042305045`]],List[1.491`,ScientificForm[0.0031907205430207306`]],List[1.492`,ScientificForm[0.003364706805684322`]],List[1.493`,ScientificForm[0.003529114711632648`]],List[1.494`,ScientificForm[0.00367520103764892`]],List[1.495`,ScientificForm[0.0037893969768483197`]],List[1.496`,ScientificForm[0.0038483114614672803`]],List[1.497`,ScientificForm[0.0038061835870495412`]],List[1.498`,ScientificForm[0.003557560962432392`]],List[1.499`,ScientificForm[0.0027902318774610966`]],List[1.5`,ScientificForm[0.`]]]

enter image description here

$\endgroup$
  • $\begingroup$ At least for the lists you have given xx and yy are of different length and so cannot be transposed. Don't you get a error message telling you that? $\endgroup$ – sebhofer Jun 16 '16 at 13:11
  • 1
    $\begingroup$ Oops sorry I edited the question to make it more lisible, but in the end created an error... xx and yy have the same length in my code. Edit: I edited my question, thanks for the catch and sorry about that. $\endgroup$ – AnSy Jun 16 '16 at 13:13
  • 2
    $\begingroup$ Can you include the complete output of Transpose[{xx,yy}] // FullForm in your question? $\endgroup$ – Mr.Wizard Jun 16 '16 at 13:24
  • 1
    $\begingroup$ @Mr.Wizard it seems indeed that the FullForm shows that my yy is written in ScientificForm. I guess the problem comes from there... $\endgroup$ – AnSy Jun 16 '16 at 13:31
  • 1
    $\begingroup$ Formatting wrappers (like ScientificForm) will indeed cause problems; in fact they appear to be one of the most common sources of problems. A frequent example is someone setting m = {{1,2}, {3,4}} // MatrixForm and then wondering why m does not act like a matrix. The documentation and software should in my opinion do a better job of warning people of this. $\endgroup$ – Mr.Wizard Jun 16 '16 at 13:49
0
$\begingroup$

Based on your original post, the data you've provided for xx and yy (after you've applied some function to derive the values you've presented) are of inconsistent lengths. Therefore, when you apply Transpose it does not work and throws an error. Below is a simple example.

Example

x = RandomInteger[{1, 100}, 100]; (*Length: 100*)
y = RandomReal[{-1, 1}, 100]; (*Length: 100*)

Output

ListPlot[Transpose[{x, y}]]

example

EDIT

Based on the information you've provided in your original post, here is a Plot I get.

Code

xx = Table[i, {i, 1.485, 1.5, .001}];
yy = {2.2005*10^(-3), 2.34527*10^(-3), 2.50062*10^(-3), 
   2.66517*10^(-3), 2.83694*10^(-3), 3.01328*10^(-3), 3.19072*10^(-3),
    3.36471*10^(-3), 3.52911*10^(-3), 3.6752*10^(-3), 3.7894*10^(-3), 
   3.84831*10^(-3), 3.80618*10^(-3), 3.55756*10^(-3), 2.79023*10^(-3),
    0.};

Length @ # & /@ {xx, yy} (* {91, 16*)

ListPlot[Transpose[{xx[[;; 16]], yy}]]

Output

example 2

$\endgroup$
  • $\begingroup$ Yes, sorry, that was a mistake on my side. I did not copy correctly xx. xx and yy in my code are of the same length. When I use ListPlot[Transpose[{xx,xx}]], I get a (linear plot), but the plot gets empty whenever I try to add yy in there. $\endgroup$ – AnSy Jun 16 '16 at 13:21
  • $\begingroup$ Try ListPlot[Transpose[{xx[[;;16]],yy[[;;16]]}]] , does it work? $\endgroup$ – e.doroskevic Jun 16 '16 at 13:24

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