python - map x, y, z values to 2D surface data
I have the following data set:
x = [50.0, 55.0, 6.6, 35.0, 32.7, 33.2, 14.9, 60.0, 44.0, 38.1]
y = [50.0, 25.0, 47.4, 34.9, 56.3, 78.4, 81.9, 73.4, 46.8 ,65.6]
z = [0.3, -1.5, 0.1, 1.0, 1.9, -0.1, -0.4, -0.1, 0.3, -0.0]
x
and y
is the location of the sample data point on a 2D surface.
z
is the value of the data sample at the location.
Essentially I want something something like this:
However, as you can see, z
values are not yet mapped into 2D grid format.
This is NOT what I want:
x = np.arange(-5, 5, 0.1)
y = np.arange(-5, 5, 0.1)
xx, yy = np.meshgrid(x, y, sparse=True)
z = np.sin(xx**2 + yy**2) / (xx**2 + yy**2)
All the examples I found online calculates z
matrix assuming some contour plot, but that's not the case for me. In my case, z
is 1D array that contains the, say, gold percentage of a rock at the sample locations, and x
and y
accounts for the location of that sample.
How can I convert the z
array into 2D matrix that accounts for the location of the sample?
At the end, I want to make a scatter plot using the 2D transformed_z
matrix.
random_sample = transformed_z[x,y]
ax.scatter(y,x,c=transformed_z, cmap=im.cmap, norm=im.norm)
python arrays matplotlib
add a comment |
I have the following data set:
x = [50.0, 55.0, 6.6, 35.0, 32.7, 33.2, 14.9, 60.0, 44.0, 38.1]
y = [50.0, 25.0, 47.4, 34.9, 56.3, 78.4, 81.9, 73.4, 46.8 ,65.6]
z = [0.3, -1.5, 0.1, 1.0, 1.9, -0.1, -0.4, -0.1, 0.3, -0.0]
x
and y
is the location of the sample data point on a 2D surface.
z
is the value of the data sample at the location.
Essentially I want something something like this:
However, as you can see, z
values are not yet mapped into 2D grid format.
This is NOT what I want:
x = np.arange(-5, 5, 0.1)
y = np.arange(-5, 5, 0.1)
xx, yy = np.meshgrid(x, y, sparse=True)
z = np.sin(xx**2 + yy**2) / (xx**2 + yy**2)
All the examples I found online calculates z
matrix assuming some contour plot, but that's not the case for me. In my case, z
is 1D array that contains the, say, gold percentage of a rock at the sample locations, and x
and y
accounts for the location of that sample.
How can I convert the z
array into 2D matrix that accounts for the location of the sample?
At the end, I want to make a scatter plot using the 2D transformed_z
matrix.
random_sample = transformed_z[x,y]
ax.scatter(y,x,c=transformed_z, cmap=im.cmap, norm=im.norm)
python arrays matplotlib
add a comment |
I have the following data set:
x = [50.0, 55.0, 6.6, 35.0, 32.7, 33.2, 14.9, 60.0, 44.0, 38.1]
y = [50.0, 25.0, 47.4, 34.9, 56.3, 78.4, 81.9, 73.4, 46.8 ,65.6]
z = [0.3, -1.5, 0.1, 1.0, 1.9, -0.1, -0.4, -0.1, 0.3, -0.0]
x
and y
is the location of the sample data point on a 2D surface.
z
is the value of the data sample at the location.
Essentially I want something something like this:
However, as you can see, z
values are not yet mapped into 2D grid format.
This is NOT what I want:
x = np.arange(-5, 5, 0.1)
y = np.arange(-5, 5, 0.1)
xx, yy = np.meshgrid(x, y, sparse=True)
z = np.sin(xx**2 + yy**2) / (xx**2 + yy**2)
All the examples I found online calculates z
matrix assuming some contour plot, but that's not the case for me. In my case, z
is 1D array that contains the, say, gold percentage of a rock at the sample locations, and x
and y
accounts for the location of that sample.
How can I convert the z
array into 2D matrix that accounts for the location of the sample?
At the end, I want to make a scatter plot using the 2D transformed_z
matrix.
random_sample = transformed_z[x,y]
ax.scatter(y,x,c=transformed_z, cmap=im.cmap, norm=im.norm)
python arrays matplotlib
I have the following data set:
x = [50.0, 55.0, 6.6, 35.0, 32.7, 33.2, 14.9, 60.0, 44.0, 38.1]
y = [50.0, 25.0, 47.4, 34.9, 56.3, 78.4, 81.9, 73.4, 46.8 ,65.6]
z = [0.3, -1.5, 0.1, 1.0, 1.9, -0.1, -0.4, -0.1, 0.3, -0.0]
x
and y
is the location of the sample data point on a 2D surface.
z
is the value of the data sample at the location.
Essentially I want something something like this:
However, as you can see, z
values are not yet mapped into 2D grid format.
This is NOT what I want:
x = np.arange(-5, 5, 0.1)
y = np.arange(-5, 5, 0.1)
xx, yy = np.meshgrid(x, y, sparse=True)
z = np.sin(xx**2 + yy**2) / (xx**2 + yy**2)
All the examples I found online calculates z
matrix assuming some contour plot, but that's not the case for me. In my case, z
is 1D array that contains the, say, gold percentage of a rock at the sample locations, and x
and y
accounts for the location of that sample.
How can I convert the z
array into 2D matrix that accounts for the location of the sample?
At the end, I want to make a scatter plot using the 2D transformed_z
matrix.
random_sample = transformed_z[x,y]
ax.scatter(y,x,c=transformed_z, cmap=im.cmap, norm=im.norm)
python arrays matplotlib
python arrays matplotlib
edited Nov 26 '18 at 10:35
SpghttCd
4,8672314
4,8672314
asked Nov 26 '18 at 0:10
Eric KimEric Kim
539418
539418
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
IIUC you just want to plot the values in z
as a color coded scatterplot with x
and y
as coordinates.
You do not need to transform z for this purpose, this can be done purely with the given three arrays as they are:
import matplotlib.pyplot as plt
x = [50.0, 55.0, 6.6, 35.0, 32.7, 33.2, 14.9, 60.0, 44.0, 38.1]
y = [50.0, 25.0, 47.4, 34.9, 56.3, 78.4, 81.9, 73.4, 46.8 ,65.6]
z = [0.3, -1.5, 0.1, 1.0, 1.9, -0.1, -0.4, -0.1, 0.3, -0.0]
plt.figure()
plt.scatter(x, y, c=z, cmap='Wistia')
cb = plt.colorbar()
cb.set_label('gold percentage of a rock (%)')
plt.xlabel('X')
plt.ylabel('Y')
for xt, yt, zt in zip(x, y, z):
plt.text(xt, yt+1, str(zt), ha='center')
I've added the values as text for faster comparison with the arrays.
add a comment |
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%2f53473289%2fpython-map-x-y-z-values-to-2d-surface-data%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
IIUC you just want to plot the values in z
as a color coded scatterplot with x
and y
as coordinates.
You do not need to transform z for this purpose, this can be done purely with the given three arrays as they are:
import matplotlib.pyplot as plt
x = [50.0, 55.0, 6.6, 35.0, 32.7, 33.2, 14.9, 60.0, 44.0, 38.1]
y = [50.0, 25.0, 47.4, 34.9, 56.3, 78.4, 81.9, 73.4, 46.8 ,65.6]
z = [0.3, -1.5, 0.1, 1.0, 1.9, -0.1, -0.4, -0.1, 0.3, -0.0]
plt.figure()
plt.scatter(x, y, c=z, cmap='Wistia')
cb = plt.colorbar()
cb.set_label('gold percentage of a rock (%)')
plt.xlabel('X')
plt.ylabel('Y')
for xt, yt, zt in zip(x, y, z):
plt.text(xt, yt+1, str(zt), ha='center')
I've added the values as text for faster comparison with the arrays.
add a comment |
IIUC you just want to plot the values in z
as a color coded scatterplot with x
and y
as coordinates.
You do not need to transform z for this purpose, this can be done purely with the given three arrays as they are:
import matplotlib.pyplot as plt
x = [50.0, 55.0, 6.6, 35.0, 32.7, 33.2, 14.9, 60.0, 44.0, 38.1]
y = [50.0, 25.0, 47.4, 34.9, 56.3, 78.4, 81.9, 73.4, 46.8 ,65.6]
z = [0.3, -1.5, 0.1, 1.0, 1.9, -0.1, -0.4, -0.1, 0.3, -0.0]
plt.figure()
plt.scatter(x, y, c=z, cmap='Wistia')
cb = plt.colorbar()
cb.set_label('gold percentage of a rock (%)')
plt.xlabel('X')
plt.ylabel('Y')
for xt, yt, zt in zip(x, y, z):
plt.text(xt, yt+1, str(zt), ha='center')
I've added the values as text for faster comparison with the arrays.
add a comment |
IIUC you just want to plot the values in z
as a color coded scatterplot with x
and y
as coordinates.
You do not need to transform z for this purpose, this can be done purely with the given three arrays as they are:
import matplotlib.pyplot as plt
x = [50.0, 55.0, 6.6, 35.0, 32.7, 33.2, 14.9, 60.0, 44.0, 38.1]
y = [50.0, 25.0, 47.4, 34.9, 56.3, 78.4, 81.9, 73.4, 46.8 ,65.6]
z = [0.3, -1.5, 0.1, 1.0, 1.9, -0.1, -0.4, -0.1, 0.3, -0.0]
plt.figure()
plt.scatter(x, y, c=z, cmap='Wistia')
cb = plt.colorbar()
cb.set_label('gold percentage of a rock (%)')
plt.xlabel('X')
plt.ylabel('Y')
for xt, yt, zt in zip(x, y, z):
plt.text(xt, yt+1, str(zt), ha='center')
I've added the values as text for faster comparison with the arrays.
IIUC you just want to plot the values in z
as a color coded scatterplot with x
and y
as coordinates.
You do not need to transform z for this purpose, this can be done purely with the given three arrays as they are:
import matplotlib.pyplot as plt
x = [50.0, 55.0, 6.6, 35.0, 32.7, 33.2, 14.9, 60.0, 44.0, 38.1]
y = [50.0, 25.0, 47.4, 34.9, 56.3, 78.4, 81.9, 73.4, 46.8 ,65.6]
z = [0.3, -1.5, 0.1, 1.0, 1.9, -0.1, -0.4, -0.1, 0.3, -0.0]
plt.figure()
plt.scatter(x, y, c=z, cmap='Wistia')
cb = plt.colorbar()
cb.set_label('gold percentage of a rock (%)')
plt.xlabel('X')
plt.ylabel('Y')
for xt, yt, zt in zip(x, y, z):
plt.text(xt, yt+1, str(zt), ha='center')
I've added the values as text for faster comparison with the arrays.
edited Nov 26 '18 at 8:08
answered Nov 26 '18 at 8:00
SpghttCdSpghttCd
4,8672314
4,8672314
add a comment |
add a comment |
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%2f53473289%2fpython-map-x-y-z-values-to-2d-surface-data%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