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

AI Thread Summary
The discussion centers on the challenge of combining two different types of 2D graphs—specifically, a ListLinePlot and a Plot—into a single figure. The original poster seeks advice on how to achieve this, expressing a preference for the ListLinePlot to resemble a block pulse graph. A solution is provided using the Graphics function to create rectangles based on the data points, which are then overlaid with the sine plot using the Show command. The poster confirms that this method works and expresses a desire to further explore how to visualize the ListLinePlot data as a block pulse graph, noting that this is simpler in MATLAB.
sugaku
Messages
16
Reaction score
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
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)
 
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.
 

Similar threads

Replies
4
Views
2K
Replies
4
Views
3K
Replies
1
Views
3K
Replies
2
Views
1K
Replies
3
Views
3K
Replies
8
Views
7K
Replies
3
Views
2K
Back
Top