Pyhon - Fill under curve, based on the value of the function












0















I have an animation of 1D heat diffusion in a copper rod. I've measured temperature in 8 locations on the rod in every second, and plotted the measured temperatures for every second/frame. (So every plot were made using an np.linspace(1,8,8) data array, which indicates the 8 measurement points on the X-axis, and their corresponding temperature values on the Y-axes.)
Every frame of the animation looks like the following (This plot changes eventually):



https://i.stack.imgur.com/iCA5x.png



At the beginning, all of the temperatures are at ~25 C°, and as we heat the right side of the rod (measurement point 8), it changes accordingly.



I want to achieve the following, preferably with matplotlib: I want to fill the space under the curve (seen on the image linked above) according to it's value in that particular point, using some nice spectrum colormap, eg. 'jet', indicating low temperatures with blue, and high with red. So in my mind, at the beginning the whole area would be pretty blue, and then as the right side gets hotter, the right side turns green, then yellow, and eventually red, and so on, drawing a spectrum at the end...



I tried to plot simply a 'jet' colormap under the curve, without any value dependence, unsuccessfully. My problems:




  1. I needed to define a 'wavelengths' array, to effectively create a good-looking spectrum, and not just 8 columns with different colors... I'm good with that.

  2. The color spectrum somewhy got plotted 'over' the curve, not under of it. A picture, which shows my problem: https://i.stack.imgur.com/3j4zK.png

  3. And my main reason I opened this entry: I don't know how to solve the problem, described above: How to color the space under the curve


I have the following code now, for simply plot this 'jet' cmap under the curve from 'x' values 1 to 8.



Defining figure first:



nrows=1
ncols=1
fig, axes = plt.subplots(nrows=nrows, ncols=ncols)

wavelengths = np.linspace(1, 8, 1000)

for i in range(0,8):
y_arr[i] = hidegmeleg[bottom_cut, i+1]

line, = axes.plot(, , c='red')

axes.set_xlim(1,8)
axes.set_ylim(20,100)


Animation (coldhot_dataset containing temperature data for every second, for all 8 thermometers). What happens here:




  1. (required) I refresh the current frame with the corresponding data.

  2. (required) I clear anything from the plot, which the fill_between from the previous frame left.

  3. I'm trying to draw a white fill_between, and top of that a cmap='jet' spectrum, following this stackoverflow thread: Matplotlib - color under curve based on spectral color


So the animation:



def animate(current_time):

x_arr = np.linspace(1,8,8)
y_arr = np.empty(8)

for i in range(0,8):
y_arr[i] = coldhot_dataset[current_time, i+1]

# Clear fill_between canvas
axes.collections.clear()

line.set_data(x_arr, y_arr)

X,Y = np.meshgrid(wavelengths, y_arr)
extent=(np.min(wavelengths), np.max(wavelengths), np.min(y_arr), np.max(y_arr))
axes.imshow(X, clim=(min(wavelengths), max(wavelengths)), extent=extent, cmap=plt.get_cmap('jet'), aspect='auto')

plt.fill_between(x_arr, y_arr, 8, color='w')

return line,


Here bottom_cut and upper_cut are just my manual crop of the dataset,
I'm using for the plot. (I cropped the dataset at bottom_cut=100s and upper_cut=2500s)



steps = [i for i in range(bottom_cut, upper_cut+1)]
anim = FuncAnimation(fig=fig, func=animate, init_func=init_func, frames=steps, interval=20, blit=False, repeat=True)

plt.show()


I hope these information would be enough. If you have any questions, just ask them. Thank you for any of your help! :)










share|improve this question




















  • 1





    I'm a bit confused on what the problem is here. The linked question would already give you the desired plot, or not? Is the animation code working, or not?

    – ImportanceOfBeingErnest
    Nov 19 '18 at 22:59
















0















I have an animation of 1D heat diffusion in a copper rod. I've measured temperature in 8 locations on the rod in every second, and plotted the measured temperatures for every second/frame. (So every plot were made using an np.linspace(1,8,8) data array, which indicates the 8 measurement points on the X-axis, and their corresponding temperature values on the Y-axes.)
Every frame of the animation looks like the following (This plot changes eventually):



https://i.stack.imgur.com/iCA5x.png



At the beginning, all of the temperatures are at ~25 C°, and as we heat the right side of the rod (measurement point 8), it changes accordingly.



I want to achieve the following, preferably with matplotlib: I want to fill the space under the curve (seen on the image linked above) according to it's value in that particular point, using some nice spectrum colormap, eg. 'jet', indicating low temperatures with blue, and high with red. So in my mind, at the beginning the whole area would be pretty blue, and then as the right side gets hotter, the right side turns green, then yellow, and eventually red, and so on, drawing a spectrum at the end...



I tried to plot simply a 'jet' colormap under the curve, without any value dependence, unsuccessfully. My problems:




  1. I needed to define a 'wavelengths' array, to effectively create a good-looking spectrum, and not just 8 columns with different colors... I'm good with that.

  2. The color spectrum somewhy got plotted 'over' the curve, not under of it. A picture, which shows my problem: https://i.stack.imgur.com/3j4zK.png

  3. And my main reason I opened this entry: I don't know how to solve the problem, described above: How to color the space under the curve


I have the following code now, for simply plot this 'jet' cmap under the curve from 'x' values 1 to 8.



Defining figure first:



nrows=1
ncols=1
fig, axes = plt.subplots(nrows=nrows, ncols=ncols)

wavelengths = np.linspace(1, 8, 1000)

for i in range(0,8):
y_arr[i] = hidegmeleg[bottom_cut, i+1]

line, = axes.plot(, , c='red')

axes.set_xlim(1,8)
axes.set_ylim(20,100)


Animation (coldhot_dataset containing temperature data for every second, for all 8 thermometers). What happens here:




  1. (required) I refresh the current frame with the corresponding data.

  2. (required) I clear anything from the plot, which the fill_between from the previous frame left.

  3. I'm trying to draw a white fill_between, and top of that a cmap='jet' spectrum, following this stackoverflow thread: Matplotlib - color under curve based on spectral color


So the animation:



def animate(current_time):

x_arr = np.linspace(1,8,8)
y_arr = np.empty(8)

for i in range(0,8):
y_arr[i] = coldhot_dataset[current_time, i+1]

# Clear fill_between canvas
axes.collections.clear()

line.set_data(x_arr, y_arr)

X,Y = np.meshgrid(wavelengths, y_arr)
extent=(np.min(wavelengths), np.max(wavelengths), np.min(y_arr), np.max(y_arr))
axes.imshow(X, clim=(min(wavelengths), max(wavelengths)), extent=extent, cmap=plt.get_cmap('jet'), aspect='auto')

plt.fill_between(x_arr, y_arr, 8, color='w')

return line,


Here bottom_cut and upper_cut are just my manual crop of the dataset,
I'm using for the plot. (I cropped the dataset at bottom_cut=100s and upper_cut=2500s)



steps = [i for i in range(bottom_cut, upper_cut+1)]
anim = FuncAnimation(fig=fig, func=animate, init_func=init_func, frames=steps, interval=20, blit=False, repeat=True)

plt.show()


I hope these information would be enough. If you have any questions, just ask them. Thank you for any of your help! :)










share|improve this question




















  • 1





    I'm a bit confused on what the problem is here. The linked question would already give you the desired plot, or not? Is the animation code working, or not?

    – ImportanceOfBeingErnest
    Nov 19 '18 at 22:59














0












0








0








I have an animation of 1D heat diffusion in a copper rod. I've measured temperature in 8 locations on the rod in every second, and plotted the measured temperatures for every second/frame. (So every plot were made using an np.linspace(1,8,8) data array, which indicates the 8 measurement points on the X-axis, and their corresponding temperature values on the Y-axes.)
Every frame of the animation looks like the following (This plot changes eventually):



https://i.stack.imgur.com/iCA5x.png



At the beginning, all of the temperatures are at ~25 C°, and as we heat the right side of the rod (measurement point 8), it changes accordingly.



I want to achieve the following, preferably with matplotlib: I want to fill the space under the curve (seen on the image linked above) according to it's value in that particular point, using some nice spectrum colormap, eg. 'jet', indicating low temperatures with blue, and high with red. So in my mind, at the beginning the whole area would be pretty blue, and then as the right side gets hotter, the right side turns green, then yellow, and eventually red, and so on, drawing a spectrum at the end...



I tried to plot simply a 'jet' colormap under the curve, without any value dependence, unsuccessfully. My problems:




  1. I needed to define a 'wavelengths' array, to effectively create a good-looking spectrum, and not just 8 columns with different colors... I'm good with that.

  2. The color spectrum somewhy got plotted 'over' the curve, not under of it. A picture, which shows my problem: https://i.stack.imgur.com/3j4zK.png

  3. And my main reason I opened this entry: I don't know how to solve the problem, described above: How to color the space under the curve


I have the following code now, for simply plot this 'jet' cmap under the curve from 'x' values 1 to 8.



Defining figure first:



nrows=1
ncols=1
fig, axes = plt.subplots(nrows=nrows, ncols=ncols)

wavelengths = np.linspace(1, 8, 1000)

for i in range(0,8):
y_arr[i] = hidegmeleg[bottom_cut, i+1]

line, = axes.plot(, , c='red')

axes.set_xlim(1,8)
axes.set_ylim(20,100)


Animation (coldhot_dataset containing temperature data for every second, for all 8 thermometers). What happens here:




  1. (required) I refresh the current frame with the corresponding data.

  2. (required) I clear anything from the plot, which the fill_between from the previous frame left.

  3. I'm trying to draw a white fill_between, and top of that a cmap='jet' spectrum, following this stackoverflow thread: Matplotlib - color under curve based on spectral color


So the animation:



def animate(current_time):

x_arr = np.linspace(1,8,8)
y_arr = np.empty(8)

for i in range(0,8):
y_arr[i] = coldhot_dataset[current_time, i+1]

# Clear fill_between canvas
axes.collections.clear()

line.set_data(x_arr, y_arr)

X,Y = np.meshgrid(wavelengths, y_arr)
extent=(np.min(wavelengths), np.max(wavelengths), np.min(y_arr), np.max(y_arr))
axes.imshow(X, clim=(min(wavelengths), max(wavelengths)), extent=extent, cmap=plt.get_cmap('jet'), aspect='auto')

plt.fill_between(x_arr, y_arr, 8, color='w')

return line,


Here bottom_cut and upper_cut are just my manual crop of the dataset,
I'm using for the plot. (I cropped the dataset at bottom_cut=100s and upper_cut=2500s)



steps = [i for i in range(bottom_cut, upper_cut+1)]
anim = FuncAnimation(fig=fig, func=animate, init_func=init_func, frames=steps, interval=20, blit=False, repeat=True)

plt.show()


I hope these information would be enough. If you have any questions, just ask them. Thank you for any of your help! :)










share|improve this question
















I have an animation of 1D heat diffusion in a copper rod. I've measured temperature in 8 locations on the rod in every second, and plotted the measured temperatures for every second/frame. (So every plot were made using an np.linspace(1,8,8) data array, which indicates the 8 measurement points on the X-axis, and their corresponding temperature values on the Y-axes.)
Every frame of the animation looks like the following (This plot changes eventually):



https://i.stack.imgur.com/iCA5x.png



At the beginning, all of the temperatures are at ~25 C°, and as we heat the right side of the rod (measurement point 8), it changes accordingly.



I want to achieve the following, preferably with matplotlib: I want to fill the space under the curve (seen on the image linked above) according to it's value in that particular point, using some nice spectrum colormap, eg. 'jet', indicating low temperatures with blue, and high with red. So in my mind, at the beginning the whole area would be pretty blue, and then as the right side gets hotter, the right side turns green, then yellow, and eventually red, and so on, drawing a spectrum at the end...



I tried to plot simply a 'jet' colormap under the curve, without any value dependence, unsuccessfully. My problems:




  1. I needed to define a 'wavelengths' array, to effectively create a good-looking spectrum, and not just 8 columns with different colors... I'm good with that.

  2. The color spectrum somewhy got plotted 'over' the curve, not under of it. A picture, which shows my problem: https://i.stack.imgur.com/3j4zK.png

  3. And my main reason I opened this entry: I don't know how to solve the problem, described above: How to color the space under the curve


I have the following code now, for simply plot this 'jet' cmap under the curve from 'x' values 1 to 8.



Defining figure first:



nrows=1
ncols=1
fig, axes = plt.subplots(nrows=nrows, ncols=ncols)

wavelengths = np.linspace(1, 8, 1000)

for i in range(0,8):
y_arr[i] = hidegmeleg[bottom_cut, i+1]

line, = axes.plot(, , c='red')

axes.set_xlim(1,8)
axes.set_ylim(20,100)


Animation (coldhot_dataset containing temperature data for every second, for all 8 thermometers). What happens here:




  1. (required) I refresh the current frame with the corresponding data.

  2. (required) I clear anything from the plot, which the fill_between from the previous frame left.

  3. I'm trying to draw a white fill_between, and top of that a cmap='jet' spectrum, following this stackoverflow thread: Matplotlib - color under curve based on spectral color


So the animation:



def animate(current_time):

x_arr = np.linspace(1,8,8)
y_arr = np.empty(8)

for i in range(0,8):
y_arr[i] = coldhot_dataset[current_time, i+1]

# Clear fill_between canvas
axes.collections.clear()

line.set_data(x_arr, y_arr)

X,Y = np.meshgrid(wavelengths, y_arr)
extent=(np.min(wavelengths), np.max(wavelengths), np.min(y_arr), np.max(y_arr))
axes.imshow(X, clim=(min(wavelengths), max(wavelengths)), extent=extent, cmap=plt.get_cmap('jet'), aspect='auto')

plt.fill_between(x_arr, y_arr, 8, color='w')

return line,


Here bottom_cut and upper_cut are just my manual crop of the dataset,
I'm using for the plot. (I cropped the dataset at bottom_cut=100s and upper_cut=2500s)



steps = [i for i in range(bottom_cut, upper_cut+1)]
anim = FuncAnimation(fig=fig, func=animate, init_func=init_func, frames=steps, interval=20, blit=False, repeat=True)

plt.show()


I hope these information would be enough. If you have any questions, just ask them. Thank you for any of your help! :)







python matplotlib plot fill spectrum






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 4:10









Aqueous Carlos

368314




368314










asked Nov 19 '18 at 22:05









Balázs PálBalázs Pál

11




11








  • 1





    I'm a bit confused on what the problem is here. The linked question would already give you the desired plot, or not? Is the animation code working, or not?

    – ImportanceOfBeingErnest
    Nov 19 '18 at 22:59














  • 1





    I'm a bit confused on what the problem is here. The linked question would already give you the desired plot, or not? Is the animation code working, or not?

    – ImportanceOfBeingErnest
    Nov 19 '18 at 22:59








1




1





I'm a bit confused on what the problem is here. The linked question would already give you the desired plot, or not? Is the animation code working, or not?

– ImportanceOfBeingErnest
Nov 19 '18 at 22:59





I'm a bit confused on what the problem is here. The linked question would already give you the desired plot, or not? Is the animation code working, or not?

– ImportanceOfBeingErnest
Nov 19 '18 at 22:59












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383308%2fpyhon-fill-under-curve-based-on-the-value-of-the-function%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383308%2fpyhon-fill-under-curve-based-on-the-value-of-the-function%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)