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

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

How to fill the area under the curve with colours?

Cornel
19-Tanzanite

How to fill the area under the curve with colours?

Hello,

Cornel_0-1689924240904.png

Cornel_4-1689924496289.png

 

Is it possible to fill the area under the graph with some colours like in this example from below?
So, from

Cornel_5-1689924533068.png
with some colour
and from

Cornel_6-1689924583255.png
with other colour 

 

Cornel_0-1689926560206.png

 

Mathcad Prime 8 file attached.

 

ACCEPTED SOLUTION

Accepted Solutions
ttokoro
20-Turquoise
(To:Cornel)

Traces, Change Type, Column Trace.

image.pngimage.png

 

image.png

View solution in original post

42 REPLIES 42
Cornel
19-Tanzanite
(To:Cornel)

and

Cornel_2-1689926643506.png

Cornel_3-1689926650186.png

 

Cornel_0-1689926624131.png

 

Cornel_4-1689926670580.png

ttokoro
20-Turquoise
(To:Cornel)

image.pngimage.png

ttokoro
20-Turquoise
(To:Cornel)

Traces, Change Type, Column Trace.

image.pngimage.png

 

image.png

Werner_E
25-Diamond I
(To:Cornel)

Maybe that way

Werner_E_1-1689933909133.png

Werner_E_2-1689933932826.png

Werner_E_3-1689933954031.pngWerner_E_4-1689933967064.png

I had not done so, but actually the color fills should be placed in the plot first and only then followed by f(x) and f(X) so these would be on top and visible!

 

 

 

Werner_E
25-Diamond I
(To:Werner_E)

You may wonder, why the usage of Fill() required the argument

Werner_E_0-1689937909877.png

This is because my Fill() function is designed to shade the area between the graphs of two functions, not necessarily between the x-axis and one function. So this expression simply is the function for the x-axis.

Werner_E_1-1689938112291.png

 

 

Cornel
19-Tanzanite
(To:Werner_E)

Do you know some similar variant like @ttokoro showed above for shading the area between the x-axis and one graph using xa and xb ranges but now for shading the area between two graphs? Or is it not possible such a variant using some xa/xb ranges for shading the are between the 2 graphs? I mean writing like that: xa = ...., xb = ...., xc= ...., xd = ...., and then plotting these variables with f(xa), f(xb), f(xc), etc, the area between 2 graphs to be colored.

Werner_E
25-Diamond I
(To:Cornel)

No, at least nothing which would be really useful and practical

Here something of very limited use which I don't consider useful and would not recommend

Werner_E_2-1689954002619.png

Use white background and stem plot in white where necessary.

 

To fill the whole center part in red as in my previous answer, you would have to use three ranges, six traces and must additionally determine the zeros (+- pi in this example) of the violet curve. Nothing I would consider using!

 

In case its not fully clear whats actually going on here, the same plot again, but the second and third trace colored differently.
Of course the first four traces are stem plots

Werner_E_3-1689954877253.png

BTW, I won't use the slow chart component for various reasons but if you are somebody who likes it, you may give it a try and  use its Traces Style:Area. Not sure how capable it is, though.

Cornel
19-Tanzanite
(To:Werner_E)

Ok. Thank you both, @Werner_E and @ttokoro. It is interesting. Mostly I will also post (in the future) for the case when someone wants to fill the area between 2 or more functions but I will keep this for another topic with this thing.

Werner_E
25-Diamond I
(To:Cornel)

One last remark - if you really want to dig into the depths of shading regions using Primes native plot, you should study the comprehensive 30-page (nothing of value comes easy) worksheet of Prof. Byrge Birkeland.

You may know his outstanding work on "Amazing Images" for real Mathcad:

Werner_E_0-1689972495572.png

Here some appetizers from his work on shading areas in Prime:

Werner_E_1-1689972608024.pngWerner_E_2-1689972659738.pngWerner_E_3-1689972758948.png

Werner_E_7-1689973003128.pngWerner_E_5-1689972932248.png

Werner_E_8-1689973075166.pngWerner_E_9-1689973096470.png

 

The attached file stems back from 2013, so I guess its in Prime 2 format.

Have fun!

 

 

 

 

 

 

 

 

 

Cornel
19-Tanzanite
(To:Werner_E)

@LucMeekes @Werner_E @ttokoro 

How to do like this?

Cornel_9-1690188093833.png
Cornel_10-1690188099666.png

Cornel_11-1690188110733.png

Cornel_12-1690188116841.png

Cornel_13-1690188124248.png

 

Cornel_8-1690188043640.png 

Cornel_2-1690187681740.png

 

Cornel_0-1690187926073.pngCornel_1-1690187933255.pngCornel_2-1690187942791.pngCornel_3-1690187949129.png

 

Cornel_4-1690187961750.pngCornel_5-1690187968914.pngCornel_6-1690187975609.png


Mathcad Prime 8 file attached.

ttokoro
20-Turquoise
(To:Cornel)

Only this plot use a tric. Others are only plot 2 Line Traces and One Column Trace. 

image.png

Cornel
19-Tanzanite
(To:ttokoro)

I do not understand how you did this. Can you attach a Mathcad Prime 8 file? Or some pictures?

Werner_E
25-Diamond I
(To:Cornel)


@Cornel wrote:

I do not understand how you did this. Can you attach a Mathcad Prime 8 file? Or some pictures?


I don't understand your question!? ttokoro was just showing the picture you posted.

The case he posted is the only one in YOUR collection which used the trick with the column trace in white and the white plot background which I had shown here -> Solved: Re: How to fill the area under the curve with colo... - PTC Community

So it not clear why you ask him how he did it!?

 

EDIT: Ah! I had not looked at your sheet and thought you were just asking what we think about this method but I now realize that you used a paint program for that pic and asked how this could be done.

The answer is: Exactly how I showed and explained it in the aforementioned thread!

The attached Prime 6 file should make it clear, I hope.

As I already wrote I dislike the usage of the range and stem plot to be used for hatching a region but it seems that its the method you like most, so use it if it fulfills your needs.

Werner_E_0-1690194958204.pngWerner_E_1-1690194968539.png

 

Cornel
19-Tanzanite
(To:Werner_E)

Ok. Now I understood. @ttokoro now it is ok. Thank you both.

Werner_E
25-Diamond I
(To:Cornel)

You may also create vertical and horizontal hatches

Werner_E_0-1690196440987.png

 

Cornel
19-Tanzanite
(To:Werner_E)

I think the Mathcad file that you have posted right now is made in Prime 9, not in Prime 6 🙂. But anyway, if you have more ideas on filling the area between 1 function and x axis, 2 or more functions, or other combinations...then post them here 😁. Thank you.

@ttokoro 
How to do for these 2 for example?

Cornel_0-1690197040913.png

Cornel_0-1690197224008.png

 

 

 

Werner_E
25-Diamond I
(To:Cornel)


if you have more ideas on filling the area between 1 function and x axis, 2 or more functions, or other combinations...then post them here 😁.

For simple fills I would use the already posted fill() function and for more sophisticated hatches the functions from Prof. Birkelands work.

 


How to do for these 2 for example?

 


Thats easy! You have just two constant functions. You may do similar as in the last example shown in the first file I posted

Werner_E_0-1690197743706.png

use range variable from 0 to 5 for your first and from 5 to 10 for your second example.

You have to use two stem plots and color them both the same to create what looks like a continuous surface similar to what I did in the following example with the red filled area

Werner_E_1-1690197919502.png

 

Cornel
19-Tanzanite
(To:Werner_E)

I succeeded..

Cornel_0-1690212624076.png

Cornel_1-1690212633317.png

 

Cornel_2-1690212640118.png

Cornel_3-1690212646362.png

 

Cornel_4-1690212659549.png

Cornel_5-1690212667722.png

 

ttokoro
20-Turquoise
(To:Cornel)

Your worksheet Hatch has an error.  Not 1i*delta x but i*delta x as shown below.

image.pngimage.pngimage.pngimage.pngimage.pngimage.png

Werner_E
25-Diamond I
(To:ttokoro)

@ttokoro 


@ttokoro wrote:

Your worksheet Hatch has an error.  Not 1i*delta x but i*delta x as shown below.


????

Its not clear what you mean?

Your posting is a reply to a post of Cornel where no worksheet was attaches at all. I also can't remember that he posted a worksheet which used a hatch function as he seems to like the method using ranges and stem plots.

The Hatch routine you show is basically the function which I posted here
Solved: Re: How to fill the area under the curve with colo... - PTC Community

and named Fill() (because hatching is rather filling with visible separate lines, I guess) but I can't spot the error to write about.

So which file with an imaginary unit 1i instead of i are you referring to?

EDIT: I found it! Its attached in another post of @Cornel  but he never used it -> Solved: Re: How to fill the area under the curve with colo... - PTC Community

 

I would also suggest applying a twist similar to what Luc had shown so its not necessary to define constant functions if we just want to limit our fill area horizontally. For demonstration purposes I used two different ways here:

Werner_E_0-1690206449589.png

This function now can be used that way:

Werner_E_1-1690206600893.png

BTW, omitting the variables F1 and F2 and using Fill() (or Hatch() in your picture) twice at the x- and y-axis is a bit inefficient as the function has to be called twice at the only benefit to spare one variable 😉

 

Sure, the same effect can also be achieved using ranges and stem traces, but editing the plot is MUCH more work!
I just notice in the pic that I still edited not enough as I seem to have forgotten to remove the point/Symbol at the second trace 😉

Werner_E_0-1690207573226.png

 

ttokoro
20-Turquoise
(To:Cornel)

Using same trick, we can plot such as hybrid plot. 

image.png

Werner_E
25-Diamond I
(To:Cornel)


@Cornel wrote:

@LucMeekes @Werner_E @ttokoro 

How to do like this?

Thats basically what I had shown here: https://community.ptc.com/t5/Mathcad/How-to-fill-the-area-under-the-curve-with-colours/m-p/888898/highlight/true#M207706

I don't like using the column trace for this purpose as its too less versatile and i sure don't like the trick using the white trace with white background.

But if thats what you want to see, use it.

Cornel
19-Tanzanite
(To:Werner_E)

What is "trick" or "tric" (as ttokoro said above)?

Werner_E
25-Diamond I
(To:Cornel)

See the Prime 6 file which I had attached to a previous answer

The trick is using white color for one of the traces to "delete" part of the first shading one. It requires the plot to use the same color (white) for the background.

LucMeekes
23-Emerald III
(To:Cornel)

For those limited to express, the following set of functions implement @Werner_E 's Fill() function with the added benefit that it also accepts scalars instead of functions, so the construct "tmp(x)<-0" is not needed:

LucMeekes_0-1690122886737.png

LucMeekes_1-1690122897795.png

example:

LucMeekes_5-1690123076916.png

LucMeekes_2-1690123041010.png

LucMeekes_3-1690123049264.png

LucMeekes_4-1690123056286.png

 

Prime4 file attached.

 

Success!
Luc

 

 

 

LucMeekes
23-Emerald III
(To:LucMeekes)

I managed to get Fill() for Prime Express into a single function:

LucMeekes_0-1690363840030.png

Success!
Luc

Cornel
19-Tanzanite
(To:LucMeekes)

@LucMeekes @Werner_E @ttokoro 
So, from my understanding, all above functions that you posted so far are for the following 2 variants:

Cornel_1-1690365491842.png

 

Cornel_0-1690365395035.png


So, for the variant when someone wants to fill with colour the area between one function f(x), two points given on the x-axis x1 and x2, and x-axis (0 line). or for the variant when someone wants to fill with colour the area between 2 functions f(x) and g(x) and 2 points given on the x-axis x1 and x2.

But when someone wants to fill with colour the area between 3 functions f(x), g(x) and h(x) and only one point given on the x-axis x1 or when someone wants to fill with colour the area between 4 functions f(x), g(x), h(x) and t(x), then is it possible something like that?

Cornel_2-1690365748843.png

 

Cornel_3-1690365767516.png

LucMeekes
23-Emerald III
(To:Cornel)

Your relations h(x) and t(x) are not functions, in the sense where a function f(x) assigns one (and only one ) value for every value of x.

That makes filling the area challenging at least, if not impossible, for arbitrary relations.

But you should definitely check that work by Byrge Birkeland.

 

Success!
Luc

Werner_E
25-Diamond I
(To:Cornel)

Have you seen my posting at the other thread about shading/coloring/filling/hatching

Werner_E_0-1690367326235.png

 

As Luc also wrote, you should have a look at Prof. Birkeland's work. And for simple dot filling  which can also be turned into a plain fill by using a lot of  dots (similar to the aforementioned filling with a lot of close vertical lines) you don't have to walk through the 30 pages, all you need is the very first  (and very short) function Dots(). If you want to hatch an area by lines (not necessarily vertical or horizontal) or  by a family of sines, or other families of curves, you have to use the other two functions he provides.

No matter what the boundaries of your region are, as long as you can set up a boolean function which determines if a point is inside the region or not, you can fill that region using his utility functions.

The Birkeland file was posted here for Prime and for real Mathcad.

Announcements

Top Tags