Mathematica - Plot two 2D graphs with different command in one figure

In summary, the speaker is having trouble combining two 2D graphs into one figure using different commands (ListLinePlot and Plot). They are looking for advice on how to create a block pulse graph using the ListLinePlot data. Another speaker provides a solution using the Graphics and Plot functions in Mathematica.
  • #1
sugaku
17
0
Good day to all,

1) I find difficulty on putting two 2D graphs into one figure. If same command it is easy to do but i have different commands, the commands are listlineplot and plot.

ListLinePlot[{{0,0},{1/8,16/257},{2/8,12272/66049},{3/8,5201936/16974593},{4/8,1842434032/4362470401},{5/8,596058685456/1121154893057},{6/8,182299004202992/288136807515649},{7/8,53603412027842576/74051159531521793},{1,15297073205596295152/
19031147999601100801}}]

Plot[Sin[t],{t,0,1}]

2) Actually i prefer above listlineplot graph to be like a block pulse graph, i coulnd't find a command to plot that kind of graph.

I do appreciate if someone out there could advice me on these matters.

thanks and best regards...
 
Physics news on Phys.org
  • #2
perhaps this :

Code:
data = {{0, 0}, {1/8, 16/257}, {2/8, 12272/66049}, {3/8, 
    5201936/16974593}, {4/8, 1842434032/4362470401}, {5/8, 
    596058685456/1121154893057}, {6/8, 
    182299004202992/288136807515649}, {7/8, 
    53603412027842576/74051159531521793}, {1, 
    15297073205596295152/19031147999601100801}};
a = Graphics[{EdgeForm[Black], Gray,
    Table[{Rectangle[{data[[i - 1, 1]], 0}, {data[[i, 1]], 
        data[[i, 2]]}]}, {i, 2, Length[data]}]}, 
   Frame -> True];
b = Plot[Sin[t], {t, 0, 1}];
Show[a, b, PlotRange -> {{0, 1}, {0, 1}}]
Basically I created a table of rectangles [xmin,ymin][xmax,ymax] using your data and overlayed it with the plot (Thats what Show is for, multiple graphics at once)
 
  • #3
Good day, thank you Hepth, it works. I will figure out how can ListLinePlot data can be visualize as block pulse graph. If I use Matlab the data simply will visualize as block pulse graph.

thank you again.
 

Related to Mathematica - Plot two 2D graphs with different command in one figure

1. How can I plot two 2D graphs in one figure using Mathematica?

To plot two 2D graphs in one figure using Mathematica, you can use the Plot and Show commands. First, use the Plot command to create the first graph, and then use the Show command to add the second graph to the same figure. Make sure to use the PlotRange option to adjust the range of the axes for both graphs.

2. Can I customize the appearance of the graphs in the figure?

Yes, you can customize the appearance of the graphs in the figure by using various options in the Plot and Show commands. Some examples include changing the color, style, and thickness of the lines, adding labels and titles, and adjusting the axes and grid lines. Refer to the Mathematica documentation for a full list of available options.

3. How can I add a legend to the figure?

To add a legend to the figure, you can use the PlotLegends option in the Plot command. This option allows you to specify the labels for each graph in the figure. Alternatively, you can use the PlotLabel option to add a label directly to the graph itself.

4. Is it possible to combine more than two graphs in one figure?

Yes, it is possible to combine more than two graphs in one figure using Mathematica. You can use the Show command multiple times to add additional graphs to the figure. Alternatively, you can use the GraphicsGrid command to arrange multiple graphs in a grid layout.

5. Can I save the figure as an image file?

Yes, you can save the figure as an image file by using the Export command. This command allows you to save the figure in various formats, such as JPEG, PNG, and PDF. You can also specify the size and resolution of the image in the Export command.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Advanced Physics Homework Help
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
7K
  • General Math
Replies
3
Views
5K
Replies
1
Views
1K
Back
Top