cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

How I can shade area under graph in Mathcad Prime 3.1?

rhanet
7-Bedrock

How I can shade area under graph in Mathcad Prime 3.1?

Hello, how I can shade area under graph in Mathcad Prime 3.1?

Area.png

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:RichardJ)

Richard Jackson wrote:

If the chart I think from a point table as it could color the area?

It could, but it would be a lot more work than what Stuart shows.

Thats true 😉

View solution in original post

22 REPLIES 22
RichardJ
19-Tanzanite
(To:rhanet)

I didn't write this, I just fished it out of my collection and converted it to Prime

StuartBruff
23-Emerald III
(To:RichardJ)

Richard Jackson wrote:

I didn't write this, I just fished it out of my collection and converted it to Prime

Neat.  For simple plots, you can also get by using the Column trace type (I've also selected the "Cross Axes at 0,0" to get rid of the space between the plot proper and the x axis).  I've doubled up on the target function to highlight the edge.

Stuart

rhanet
7-Bedrock
(To:rhanet)

If the chart I think from a point table as it could color the area?

Tabla.png

StuartBruff
23-Emerald III
(To:rhanet)

Ricardo Huaranga wrote:

If the chart I think from a point table as it could color the area?

Do you mean something like this?

If so, just click on the y-axis variable you want (i in this case) and select "Column Trace" from the "Change Type" drop down.

Stuart

Hi Stuart, thank you very much for your help.

I want to make is this:

plot.png

The red graph from data T i vs created. I want to color the green area.

StuartBruff
23-Emerald III
(To:rhanet)

Ricardo Huaranga wrote:

Hi Stuart, thank you very much for your help.

I want to make is this:

plot.png

The red graph from data T i vs created. I want to color the green area.

I'm not sure that Prime will do what you want.  Where did you get that plot?   (And that colour green - it's not on my palette?).  I haven't looked at Werner's solution, but the nearest I could get using just basic settings was this:

But both our solutions need 2 traces, not the one that your plot shows.

Stuart

RichardJ
19-Tanzanite
(To:StuartBruff)

I'm not sure that Prime will do what you want.  Where did you get that plot?   (And that colour green - it's not on my palette?).

I'm not sure Prime can do this either.

But it can be done

StuartBruff
23-Emerald III
(To:RichardJ)

Richard Jackson wrote:

I'm not sure that Prime will do what you want.  Where did you get that plot?   (And that colour green - it's not on my palette?).

I'm not sure Prime can do this either.

But it can be done

Hey!  Your phone's got a selfie facility too!

Stuart

RichardJ
19-Tanzanite
(To:rhanet)

If the chart I think from a point table as it could color the area?

It could, but it would be a lot more work than what Stuart shows.

Werner_E
25-Diamond I
(To:RichardJ)

Richard Jackson wrote:

If the chart I think from a point table as it could color the area?

It could, but it would be a lot more work than what Stuart shows.

Thats true 😉

rhanet
7-Bedrock
(To:Werner_E)

Werner, Thank you very much, this is just what I wanted.

How can I do this:

plot.png

Werner_E
25-Diamond I
(To:rhanet)

First approach could be to first plot the area underneath T-p in yellow over the full range as before.

Then you'll have to create a new vector of ordinate values, consisting of the values in i1 and surrounded by the appropriate values of p as the first and last values. Use then "shade" to color the area under that new vector in blue.

Or you write a routine similar to mine which shades the area of two graphs given by vectors. Then you would plot the area under p in blue first and the the area between p and i2 in yellow.

Writing that routine would even be more work, because to make it a real utility function you would also have to consider the situation, where the values in the abscissa vectors of both graphs don't match.

For shading the area under a function oder between two functions given by vectors can also use the routines which are presented or referred to here Shading Graph

as you can turn the vectors into a functions by using some sort of interpolation, e.g. linear interpolation. But unfortunately this will not work in your case, as "linterp" will not work on abscissa vectors containing equal values which you need because of the vertical line segments.

An option might be to write your own modified routine for linear interpolation.

Werner

rhanet
7-Bedrock
(To:Werner_E)

Thank you very much for your help Werner, based on your file shade I could do.

plot.png

plot1.png

plot2.png

The expected result is obtained with two functions and overlaying graphics shade:

SHADE 1

shade1.png

SHADE 2:

shade2.png

Here is the file for which interest them:

Werner_E
25-Diamond I
(To:rhanet)

Unfortunately my Prime 3.0 version can't read files in P3.1 format, so I am using a somewhat different vector.

I played around with my second idea and wrote a linterp2 function, which does not choke on equal abscissa values.

Using a short shade2 routine which shades the area between two graphs in a given interval I could also achieve what you wanted by turning the vectors into linear interpolated functions.

"fill1" could have been created using my original "shade", too.

Regards, Werner

Werner_E
25-Diamond I
(To:rhanet)

Here is a slightly different approach with an extra function for the border line.

That way you don't have to work with overlapping shaded regions but can shade the exact regions you want to.

Werner

Werner_E
25-Diamond I
(To:rhanet)

OK, her at last a version especially for Richard and Stuart

Werner

StuartBruff
23-Emerald III
(To:Werner_E)

Werner Exinger wrote:

OK, her at last version especially for Richard and Stuart

RichardJ
19-Tanzanite
(To:Werner_E)

OK, her at last a version especially for Richard and Stuart

      

RichardJ
19-Tanzanite
(To:Werner_E)

I just found this lying around on my hard drive, so I thought I would add it to the thread for completeness. It was written by Byrge Birkeland, and as you might expect it's the (30 page) tour de force on shading

Werner_E
25-Diamond I
(To:RichardJ)

Yes -> Hatch.zip

Prof. Birkelands work is always a pleasure to study - his "Amazing Images" E-Book is a legendary classic.

But his work is in no way easy to digest for the reader, so I hesitated to mention his work here 😉

Shading/Hatching an area is quite often needed and many very simple plot programs are able to do it, so there should be an easy way to do it implemented in Mathcad.

But I know - the wish list is very long and it got even much longer when Prime was introduced as we now have to wish things we already were used to in Mathcad.

Werner

StuartBruff
23-Emerald III
(To:Werner_E)

Werner Exinger wrote:

Shading/Hatching an area is quite often needed and many very simple plot programs are able to do it, so there should be an easy way to do it implemented in Mathcad.

But I know - the wish list is very long and it got even much longer when Prime was introduced as we now have to wish things we already were used to in Mathcad.

One other thing that this thread shows is the need to have a step display.   I'm guessing that the intended data set for the OP's plotting doesn't come with the data duplicated at each T index.   In which case, it's probably useful to have a "step" generating function.  I've used you nice little image plotting function to give a slightly more mathematical feel to the plot than Richard's and my images do...

Stuart

(In case it's not clear from the images, we're using Simpson's Rule to evaluate the integral of Homer from doughnut to beer. )

Werner_E
25-Diamond I
(To:StuartBruff)

Nice work, as usual!

I've used you nice little image plotting function to give a slightly more mathematical feel to the plot than Richard's and my images do...

   I like that spikedmath.com and mathfail.com sites a lot!

Werner

Announcements

Top Tags