Pyhon - Fill under curve, based on the value of the function
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:
- 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.
- 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
- 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:
- (required) I refresh the current frame with the corresponding data.
- (required) I clear anything from the plot, which the
fill_between
from the previous frame left. - I'm trying to draw a white
fill_between
, and top of that acmap='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
add a comment |
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:
- 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.
- 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
- 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:
- (required) I refresh the current frame with the corresponding data.
- (required) I clear anything from the plot, which the
fill_between
from the previous frame left. - I'm trying to draw a white
fill_between
, and top of that acmap='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
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
add a comment |
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:
- 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.
- 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
- 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:
- (required) I refresh the current frame with the corresponding data.
- (required) I clear anything from the plot, which the
fill_between
from the previous frame left. - I'm trying to draw a white
fill_between
, and top of that acmap='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
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:
- 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.
- 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
- 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:
- (required) I refresh the current frame with the corresponding data.
- (required) I clear anything from the plot, which the
fill_between
from the previous frame left. - I'm trying to draw a white
fill_between
, and top of that acmap='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
python matplotlib plot fill spectrum
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
add a comment |
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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