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

Click For Summary
SUMMARY

This discussion addresses the challenge of plotting two distinct 2D graphs in a single figure using Mathematica. The user seeks to combine a ListLinePlot and a Plot of the sine function. A solution is provided that utilizes the Graphics function to create a block pulse graph from the ListLinePlot data and overlays it with the sine plot using the Show function. The final code effectively combines these visualizations, demonstrating the capability of Mathematica to handle multiple graphics simultaneously.

PREREQUISITES
  • Familiarity with Mathematica syntax and functions
  • Understanding of ListLinePlot and Plot functions in Mathematica
  • Basic knowledge of graphical representation in Mathematica
  • Experience with the Show function for combining graphics
NEXT STEPS
  • Explore advanced plotting techniques in Mathematica
  • Learn about the Graphics function for custom visualizations
  • Investigate the creation of block pulse graphs in Mathematica
  • Study the use of Table and Rectangle functions for graphical data representation
USEFUL FOR

Mathematica users, data visualizers, and anyone interested in combining multiple graphical representations in a single figure.

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 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
6K
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 8 ·
Replies
8
Views
7K