I have a ListLogLogPlot, for example:

data1 = ListLogLogPlot[Table[{i^2, i^(1/3)}, {i, 1, 20, 1}]]

Note: I know that there is no need to export the data in the example, because the data are explicit as specified in the Table, however, in my real problem, the data in Table are calculated from the other data, which are not explicit. Thus, I try to export the data using the following code into a .txt or .dat file for the subsequent processing.

datapart1 = Cases[data1, Line[data_] :> data, -4, 1][[1]];

Export["datapart1.txt", datapart1, "Table"]

However, the first line gives me an error:

Part::partw: Part 1 of {} does not exist. >>

Accordingly, the export gives just an empty file.


closed as off-topic by Szabolcs, user9660, m_goldberg, MarcoB, Bob Hanlon Jan 18 '16 at 17:53

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Szabolcs, Community, m_goldberg, MarcoB, Bob Hanlon
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ I don't understand the question. ListLogLogPlot always takes data that is explicitly specified as data points. If you already have this data, why can't you export it directly? If you don't already have this data, how can you use ListLogLogPlot at all? $\endgroup$ – Szabolcs Jan 18 '16 at 8:46
  • 1
    $\begingroup$ I understood this such that you somehow produce a list. In your example above this list is given by lst=Table[{i^2, i^(1/3)}, {i, 1, 20, 1}] , but in a real case - by a much more complex procedure, right? Then you need to make another list out of it, such that it can be plotted as a log-log plot. Am I right? If so, you can do a simple trick. After you have created a list lst do the following: lst/.{x_,y_}->{Log[x],Log[y]} . Done. This you may export. Have fun! $\endgroup$ – Alexei Boulbitch Jan 18 '16 at 8:57
  • $\begingroup$ Hi, @ Alexei Boulbitch, you got the point of my problem. Trying it. Thanks! $\endgroup$ – W. Robin Jan 18 '16 at 9:42
  • 1
    $\begingroup$ @AlexeiBoulbitch, in this case you don't have to even use a replacement rule, you can just use Log[lst] since Log is Listable. $\endgroup$ – Jason B. Jan 18 '16 at 10:00
  • $\begingroup$ Based on the comments the OP effectively wanted to use ListLogLogPlot to compute (not plot) the logarithm of the data. As Jason notes, this should be done with Log instead. Voting to close as simple mistake. Please clarify if I misunderstood. $\endgroup$ – Szabolcs Jan 18 '16 at 11:46

You are trying to get Cases of Line in your plot. There are no lines in your plot, only points.

data1 = 
  ListLogLogPlot[Table[{i^2, i^(1/3)}, {i, 1, 20, 1}]];
Cases[data1, Point[data_] :> data, Infinity]
(* {{{0., 0.}, {1.38629, 0.231049}, {2.19722, 
   0.366204}, {2.77259, 0.462098}, {3.21888, 0.536479}, {3.58352, 
   0.597253}, {3.89182, 0.648637}, {4.15888, 0.693147}, {4.39445, 
   0.732408}, {4.60517, 0.767528}, {4.79579, 0.799298}, {4.96981, 
   0.828302}, {5.1299, 0.854983}, {5.27811, 0.879686}, {5.4161, 
   0.902683}, {5.54518, 0.924196}, {5.66643, 0.944404}, {5.78074, 
   0.963457}, {5.88888, 0.98148}, {5.99146, 0.998577}}} *)

You had originally used a [[1]] in your code, which for just one plotted list had the effect of removing some extraneous curly brackets. But for multiple plotted lists, it takes just the first list. Without the [[1]], it is more general,

 ListLogLogPlot[Table[{i^2, i^(1/3 + m)}, {m, 0, 4, 1}, {i, 1, 20, 1}]]
 , Point[data_] :> data, Infinity]
(* {{{0., 0.}, {1.38629, 0.231049}, {2.19722, 
   0.366204}, {2.77259, 0.462098},............
   ......................... {5.78074, 12.5249}, {5.88888, 
   12.7592}, {5.99146, 12.9815}}} *)

Of course, as Szabolcs pointed out, you can get the same thing by typing

N @ Log @ Table[{i^2, i^(1/3 + m)}, {m, 0, 4, 1}, {i, 1, 20, 1}]
  • $\begingroup$ @ Jason B, thanks. Can I change Line into Point within Cases to export the point coordinates? Because my ListLogLogPlot takes very long time to generate the curve. $\endgroup$ – W. Robin Jan 18 '16 at 9:48
  • $\begingroup$ @W.Robin that works as well. As long as you have the plot in a notebook you can extract the underlying points. $\endgroup$ – Jason B. Jan 18 '16 at 10:05
  • $\begingroup$ @ Jason B, there are 5 Table in my ListLogLogPlot, they are placed in a bracket as {Table1, Table2, ..., Table5}. Use Cases[data1, Point[data_] :> data, -4, 1][[1]], it can only export part of the points, seems only those in the first Table. Help... $\endgroup$ – W. Robin Jan 18 '16 at 10:30
  • $\begingroup$ Right on, that's because of the 1 you gave as the fourth argument to Cases and also because of the [[1]] you had at the end. see the update above. $\endgroup$ – Jason B. Jan 18 '16 at 10:42

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