0
$\begingroup$

The code below generates the plot "z" and gives a name to the "Show" function.

paraName = firstProject;
z = ListPlot[{{0, 5}, {1, 4}, {2, 3}, {3, 2}, {4, 1}, {5, 0}}];
fontSize = 12;
ToExpression[
 ToString[paraName] <> 
  "Pack=Show[z,Frame\[Rule]True,Axes\[Rule]False,LabelStyle\[Rule]{\
FontFamily\[Rule]Arial,FontSize\[Rule]14},FrameLabel\[Rule]{xAxis \
(mm)," <> ToString[paraName ] <> "(hr)}]"]

In x and y-axis labels, it seems that ToExpression does not interpret properly the parenthesis. Instead of showing : "xAxis (mm)" or "firstProject (hr)", the parenthesis are skipped: "mm xAxis" and "firstProject hr". It looks like ToExpression interprets "xAxis (mm)" for example as the product of xAxis and mm.

| improve this question | | | | |
$\endgroup$
  • $\begingroup$ your label strings need to be quoted with escaped quotes, \"xaxis (mm)\" $\endgroup$ – george2079 Feb 10 '15 at 3:01
1
$\begingroup$

just confirming what i said in comment, this works:

 paraName = firstProject;
 z = ListPlot[{{0, 5}, {1, 4}, {2, 3}, {3, 2}, {4, 1}, {5, 0}}];
 fontSize = 12;
 ToExpression[
  ToString[paraName] <> "Pack=Show[z,Frame\[Rule]True,Axes\[Rule]False,
   LabelStyle\[Rule]{FontFamily\[Rule]Arial,FontSize\[Rule]14},
   FrameLabel\[Rule]{\"xAxis (mm)\",\"" <> ToString[paraName] <> "(hr)\"}]"]
                     ^^          ^^ ^^                                ^^

In your origial incarnation xaxis (mm) is not a string (within the string) so ToExpression treats it as the multiplication of the symbols xAxis and mm.

| improve this answer | | | | |
$\endgroup$
1
$\begingroup$

Why not take an easier approach without ToExpression?

paraName = "firstProject";
ListPlot[{{0, 5}, {1, 4}, {2, 3}, {3, 2}, {4, 1}, {5, 0}},
  Axes -> False,
  Frame -> True,
  FrameLabel -> {"xAxis (mm)", paraName <> " (hr)"},
  LabelStyle -> {FontFamily -> "Arial", FontSize -> 14}]

plot

Update

Since the OP insists in a comment that he must use Show, I suggest it might be done this way, which is not all that different the my first attempt.

paraName = "firstProject";
z = ListPlot[{{0, 5}, {1, 4}, {2, 3}, {3, 2}, {4, 1}, {5, 0}}];
myPlot[plot_, name_] := 
 Show[plot, 
   Axes -> False, Frame -> True, 
   FrameLabel -> {"xAxis (mm)", name <> " (hr)"}, 
   LabelStyle -> {FontFamily -> "Arial", FontSize -> 14}]
pack = myPlot[z, paraName]

show

| improve this answer | | | | |
$\endgroup$
  • $\begingroup$ I need to give the name Show[ $\endgroup$ – JMarc Feb 9 '15 at 23:35
  • $\begingroup$ Without getting into too much details, I need to give the value of paraName to Show[z,....], i.e firstProject=Show[z...]. All the code is actually in a For loop, and at each iteration the value of paraName changes, and the content of the list to plot also. Once out of the loop, all the graphs are shown in an 2D grid using GraphicsGrid. $\endgroup$ – JMarc Feb 9 '15 at 23:41
  • $\begingroup$ Thanks a lot. This works perfectly. $\endgroup$ – JMarc Feb 10 '15 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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