Plotting Multiple values on different domains

Click For Summary

Discussion Overview

The discussion revolves around plotting multiple constant values on different intervals using Mathematica. Participants explore methods to ensure that all plots appear on the same axes and address the inclusion of legends for clarity.

Discussion Character

  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant describes an attempt to plot constant values over 1-unit intervals but encounters issues with the plots not aligning on the same axes.
  • Another participant suggests using the Show function to combine multiple plots generated in a table, ensuring they are displayed on the same graph.
  • A later reply addresses the issue of having multiple legends when plotting and proposes adding a PlotLegend directly within the Plot function to manage this.

Areas of Agreement / Disagreement

Participants generally agree on the method of using Show to combine plots, but there is an ongoing discussion about the best way to handle plot legends, indicating some uncertainty or differing preferences.

Contextual Notes

Participants have not resolved the best approach for managing plot legends when multiple plots are generated, and there may be assumptions about familiarity with Mathematica's plotting functions.

member 428835
Hi PF!

I have a list of numbers, and I'm trying to plot each constant value on a 1-unit long interval. What I'm trying is this

Code:
a = Table[i, {i, 2, 8}];
For[i = 1, i < 5, i++, Plot[a[[i]], {x, i - 1, i}] // Print]

but that generates plots that are not on the same axes. Any help?
 
Last edited by a moderator:
Physics news on Phys.org
I have edited your post to put the Mathematica code inside code tags. Otherwise, it doesn't come out properly.

What you need to do is to generate the plots inside a table, and then use Show to plots all of them on the same graph:
Code:
Show[Table[Plot[a[[i]], {x, i - 1, i}], {i, 1, 4}], PlotRange -> {{0, 4}, {0, 6}}]
 
  • Like
Likes   Reactions: member 428835
DrClaude said:
I have edited your post to put the Mathematica code inside code tags. Otherwise, it doesn't come out properly.

What you need to do is to generate the plots inside a table, and then use Show to plots all of them on the same graph:
Code:
Show[Table[Plot[a[[i]], {x, i - 1, i}], {i, 1, 4}], PlotRange -> {{0, 4}, {0, 6}}]
Hey thanks! so if I have ##a## and ##b##, do you know how to create a plot legend, because when I add PlotLegends inside the table I obviously get 4 legends? If statement or is there a better way?
 
Last edited by a moderator:
You can add a PlotLegend in the Plot, e.g,
Code:
Show[Table[
  Plot[a[[i]], {x, i - 1, i}, PlotLegends -> {i}], {i, 1, 4}], PlotRange -> {{0, 4}, {0, 6}}]
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K