Group Abstract Group Abstract

Message Boards Message Boards

1
|
5.8K Views
|
5 Replies
|
4 Total Likes
View groups...
Share
Share this post:

ChartLegends can be orphans

Posted 12 years ago

Simple example from the documentation.

mychart = 
 BarChart[{1, 2, 3}, ChartStyle -> "Pastel", 
  ChartLegends -> {"John", "Mary", "Bob"}]

The legends appear in the output cell but if one right-clicks on the image only the chart proper is selected, the legends remain outside the image. See "naked chart.pdf"

If the chart is exported the legends do get included.

Export[NotebookDirectory[] <> "barchart.pdf", mychart]

See attached.

Attachments:
POSTED BY: Douglas Kubler
5 Replies
Posted 12 years ago
POSTED BY: Douglas Kubler
Posted 12 years ago

I tried using Placed[] for the legends. When off the chart body they were orphaned. At the Center they became part of the image. Right-click and save everything works. Center was an unaesthetic position so I tried a few numbers (in a positioning system yet to be decoded). Zero (0) did a fair job.

mychart = 
 BarChart[{1, 2, 3}, ChartStyle -> "Pastel", 
  ChartLegends -> Placed[{"John", "Mary", "Bob"}, {0, Center}]]

The Head of mychart is still Legended.

Attachments:
POSTED BY: Douglas Kubler
Posted 12 years ago
POSTED BY: David Keith

The root of the behavior, I believe, is that that the Head of mychart is not Graphics but, rather, Legended

In[6]:= Head[mychart]

Out[6]= Legended

Hence the selection of the Graphics within the Legended'd displayed graph. This behavior then will occur whenever one uses Legended around a graphic or any other expression.

I noticed this some while ago and wondered about the design decision to have an option to a graphics function yield something with a head that is not Graphics. The main issue is that the inclusion of a Ledgending option to a Graphics function has the unexpected side effect of changing the resulting output's Head. Side effects generally are a no-no in software design.

POSTED BY: David Reiss
Posted 12 years ago

I have also noticed this. The unfortunate result is that selecting the graphic, right-clicking, and using "Save graphic as" can only save the plot without legends. Any attempt to use copy or ctrl-c results in the text form in WL, not a graphic. This forces one to explicitly export graphics for presentations and reports, rather than being able to do a quick copy-paste or save-as.

Maybe there is a better way? Already in WL?

POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard