How to draw a contour plot with two 2D array (x,y) and 0D array i.e., an scalar (z)?How to merge two dictionaries in a single expression?How do you get the logical xor of two variables in Python?How to iterate through two lists in parallel?How do I concatenate two lists in Python?How to change the font size on a matplotlib plotHow to put the legend out of the plotHow to define a two-dimensional array in Pythonpython: how to identify if a variable is an array or a scalarHow to make IPython notebook matplotlib plot inlineHow to draw vertical lines on a given plot in matplotlib?
Why do some games show lights shine thorugh walls?
Why does the Saturn V have standalone inter-stage rings?
How was Hillel permitted to go to the skylight to hear the shiur
How is a harsesis different from any old Goa’uld
Trainee keeps missing deadlines for independent learning
If I wouldn't want to read the story, is writing it still a good idea?
Links to webpages in books
Are all instances of trolls turning to stone ultimately references back to Tolkien?
How do I professionally let my manager know I'll quit over smoking in the office?
Apply brace expansion in "reverse order"
What does the hyphen "-" mean in "tar xzf -"?
Why did pressing the joystick button spit out keypresses?
(Newbie question)Why is voltage measurement of circuit different when switch is on?
If you snatch, I trade
What are the penalties for overstaying in USA?
How risky is real estate?
How would modern naval warfare have to have developed differently for battleships to still be relevant in the 21st century?
How can I politely work my way around not liking coffee or beer when it comes to professional networking?
Why do some professors with PhDs leave their professorships to teach high school?
How does a monk's Martial Arts feature modify damage done by magical monk weapons?
Should developer taking test phones home or put in office?
What does "play with your toy’s toys" mean?
How to create a Tetrix/Sierpinski Tetrahedron fractal radiating from 0,0,0 ? Python or nodes
Loss of power when I remove item from the outlet
How to draw a contour plot with two 2D array (x,y) and 0D array i.e., an scalar (z)?
How to merge two dictionaries in a single expression?How do you get the logical xor of two variables in Python?How to iterate through two lists in parallel?How do I concatenate two lists in Python?How to change the font size on a matplotlib plotHow to put the legend out of the plotHow to define a two-dimensional array in Pythonpython: how to identify if a variable is an array or a scalarHow to make IPython notebook matplotlib plot inlineHow to draw vertical lines on a given plot in matplotlib?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to draw a contour plot using two 2D arrays (both has the shape (6,1) as x and y and my third data (z) is the calculated RMS between the x vector (x list has just 6 items) and y vector (y list has 600 items). RMS value is a scalar for each point. I mean I have one RMS value for each point. when I try to draw a contour plot using x, y, z the following error arises:
TypeError: Input z must be a 2D array
How to solve this problem?
Thanks in advance
import numpy
import matplotlib.pyplot as plt
from math import sqrt
def Cumulative_Sensitivity (depth, coil_spacing, coil_position):
global z
global s
z=numpy.array(depth)
s=numpy.array(coil_spacing)
if coil_position == "hcp":
cs=(4*(z/s)**2+1)**(-0.5)
cs=numpy.array(cs)
elif coil_position == "vcp":
cs=(4*(z/s)**2+1) **(0.5)-2*(z/s)
cs=numpy.array(cs)
return cs
def forward_model (sigma, depth, coil_spacing, coil_position):
global cs
global cond_true
global cond_apps
cond_true=numpy.array(sigma)
cond_apps=numpy.zeros(len(coil_spacing))
for i in range (0, len(coil_spacing)):
cs= Cumulative_Sensitivity (depth, coil_spacing[i], coil_position)
cond_app = sum(cond_true[:-1]*(cs[:-1]-cs[1:]))
cond_app = cond_app + cond_true[-1]*(cs[-1])
cond_apps[i] = cond_app
return cond_apps
# s1=30mS/m and s2=50mS/m, z=1m
sa_1=forward_model ([30, 50], [0, 1], [0.32], "hcp")
sa_2=forward_model ([30, 50], [0, 1], [0.71], "hcp")
sa_3=forward_model ([30, 50], [0, 1], [1.18], "hcp")
sa_4=forward_model ([30, 50], [0, 1], [0.32], "vcp")
sa_5=forward_model ([30, 50], [0, 1], [0.71], "vcp")
sa_6=forward_model ([30, 50], [0, 1], [1.18], "vcp")
data=numpy.array([sa_1, sa_2, sa_3, sa_4, sa_5, sa_6])
#
for i in range (10,110, 10):
for j in range (10,110, 10):
cond_HC1=forward_model ([j, i], [0, 1], [0.32], "hcp")
cond_HC2=forward_model ([j, i], [0, 1], [0.71], "hcp")
cond_HC3=forward_model ([j, i], [0, 1], [1.18], "hcp")
cond_VC1=forward_model ([j, i], [0, 1], [0.32], "vcp")
cond_VC2=forward_model ([j, i], [0, 1], [0.71], "vcp")
cond_VC3=forward_model ([j, i], [0, 1], [1.18], "vcp")
predicted=numpy.array([cond_HC1, cond_HC2, cond_HC3, cond_VC1, cond_VC2, cond_VC3])
rms=numpy.array(sqrt(sum((predicted - data)**2).mean()))
x = numpy.linspace(10,100,10)
y = numpy.linspace(10,100,10)
X,Y=numpy.meshgrid(x,y)
Z=rms
contour = plt.contour(X, Y, Z)python
add a comment |
I'm trying to draw a contour plot using two 2D arrays (both has the shape (6,1) as x and y and my third data (z) is the calculated RMS between the x vector (x list has just 6 items) and y vector (y list has 600 items). RMS value is a scalar for each point. I mean I have one RMS value for each point. when I try to draw a contour plot using x, y, z the following error arises:
TypeError: Input z must be a 2D array
How to solve this problem?
Thanks in advance
import numpy
import matplotlib.pyplot as plt
from math import sqrt
def Cumulative_Sensitivity (depth, coil_spacing, coil_position):
global z
global s
z=numpy.array(depth)
s=numpy.array(coil_spacing)
if coil_position == "hcp":
cs=(4*(z/s)**2+1)**(-0.5)
cs=numpy.array(cs)
elif coil_position == "vcp":
cs=(4*(z/s)**2+1) **(0.5)-2*(z/s)
cs=numpy.array(cs)
return cs
def forward_model (sigma, depth, coil_spacing, coil_position):
global cs
global cond_true
global cond_apps
cond_true=numpy.array(sigma)
cond_apps=numpy.zeros(len(coil_spacing))
for i in range (0, len(coil_spacing)):
cs= Cumulative_Sensitivity (depth, coil_spacing[i], coil_position)
cond_app = sum(cond_true[:-1]*(cs[:-1]-cs[1:]))
cond_app = cond_app + cond_true[-1]*(cs[-1])
cond_apps[i] = cond_app
return cond_apps
# s1=30mS/m and s2=50mS/m, z=1m
sa_1=forward_model ([30, 50], [0, 1], [0.32], "hcp")
sa_2=forward_model ([30, 50], [0, 1], [0.71], "hcp")
sa_3=forward_model ([30, 50], [0, 1], [1.18], "hcp")
sa_4=forward_model ([30, 50], [0, 1], [0.32], "vcp")
sa_5=forward_model ([30, 50], [0, 1], [0.71], "vcp")
sa_6=forward_model ([30, 50], [0, 1], [1.18], "vcp")
data=numpy.array([sa_1, sa_2, sa_3, sa_4, sa_5, sa_6])
#
for i in range (10,110, 10):
for j in range (10,110, 10):
cond_HC1=forward_model ([j, i], [0, 1], [0.32], "hcp")
cond_HC2=forward_model ([j, i], [0, 1], [0.71], "hcp")
cond_HC3=forward_model ([j, i], [0, 1], [1.18], "hcp")
cond_VC1=forward_model ([j, i], [0, 1], [0.32], "vcp")
cond_VC2=forward_model ([j, i], [0, 1], [0.71], "vcp")
cond_VC3=forward_model ([j, i], [0, 1], [1.18], "vcp")
predicted=numpy.array([cond_HC1, cond_HC2, cond_HC3, cond_VC1, cond_VC2, cond_VC3])
rms=numpy.array(sqrt(sum((predicted - data)**2).mean()))
x = numpy.linspace(10,100,10)
y = numpy.linspace(10,100,10)
X,Y=numpy.meshgrid(x,y)
Z=rms
contour = plt.contour(X, Y, Z)python
please show some code
– David Jones
Mar 25 at 8:59
add a comment |
I'm trying to draw a contour plot using two 2D arrays (both has the shape (6,1) as x and y and my third data (z) is the calculated RMS between the x vector (x list has just 6 items) and y vector (y list has 600 items). RMS value is a scalar for each point. I mean I have one RMS value for each point. when I try to draw a contour plot using x, y, z the following error arises:
TypeError: Input z must be a 2D array
How to solve this problem?
Thanks in advance
import numpy
import matplotlib.pyplot as plt
from math import sqrt
def Cumulative_Sensitivity (depth, coil_spacing, coil_position):
global z
global s
z=numpy.array(depth)
s=numpy.array(coil_spacing)
if coil_position == "hcp":
cs=(4*(z/s)**2+1)**(-0.5)
cs=numpy.array(cs)
elif coil_position == "vcp":
cs=(4*(z/s)**2+1) **(0.5)-2*(z/s)
cs=numpy.array(cs)
return cs
def forward_model (sigma, depth, coil_spacing, coil_position):
global cs
global cond_true
global cond_apps
cond_true=numpy.array(sigma)
cond_apps=numpy.zeros(len(coil_spacing))
for i in range (0, len(coil_spacing)):
cs= Cumulative_Sensitivity (depth, coil_spacing[i], coil_position)
cond_app = sum(cond_true[:-1]*(cs[:-1]-cs[1:]))
cond_app = cond_app + cond_true[-1]*(cs[-1])
cond_apps[i] = cond_app
return cond_apps
# s1=30mS/m and s2=50mS/m, z=1m
sa_1=forward_model ([30, 50], [0, 1], [0.32], "hcp")
sa_2=forward_model ([30, 50], [0, 1], [0.71], "hcp")
sa_3=forward_model ([30, 50], [0, 1], [1.18], "hcp")
sa_4=forward_model ([30, 50], [0, 1], [0.32], "vcp")
sa_5=forward_model ([30, 50], [0, 1], [0.71], "vcp")
sa_6=forward_model ([30, 50], [0, 1], [1.18], "vcp")
data=numpy.array([sa_1, sa_2, sa_3, sa_4, sa_5, sa_6])
#
for i in range (10,110, 10):
for j in range (10,110, 10):
cond_HC1=forward_model ([j, i], [0, 1], [0.32], "hcp")
cond_HC2=forward_model ([j, i], [0, 1], [0.71], "hcp")
cond_HC3=forward_model ([j, i], [0, 1], [1.18], "hcp")
cond_VC1=forward_model ([j, i], [0, 1], [0.32], "vcp")
cond_VC2=forward_model ([j, i], [0, 1], [0.71], "vcp")
cond_VC3=forward_model ([j, i], [0, 1], [1.18], "vcp")
predicted=numpy.array([cond_HC1, cond_HC2, cond_HC3, cond_VC1, cond_VC2, cond_VC3])
rms=numpy.array(sqrt(sum((predicted - data)**2).mean()))
x = numpy.linspace(10,100,10)
y = numpy.linspace(10,100,10)
X,Y=numpy.meshgrid(x,y)
Z=rms
contour = plt.contour(X, Y, Z)python
I'm trying to draw a contour plot using two 2D arrays (both has the shape (6,1) as x and y and my third data (z) is the calculated RMS between the x vector (x list has just 6 items) and y vector (y list has 600 items). RMS value is a scalar for each point. I mean I have one RMS value for each point. when I try to draw a contour plot using x, y, z the following error arises:
TypeError: Input z must be a 2D array
How to solve this problem?
Thanks in advance
import numpy
import matplotlib.pyplot as plt
from math import sqrt
def Cumulative_Sensitivity (depth, coil_spacing, coil_position):
global z
global s
z=numpy.array(depth)
s=numpy.array(coil_spacing)
if coil_position == "hcp":
cs=(4*(z/s)**2+1)**(-0.5)
cs=numpy.array(cs)
elif coil_position == "vcp":
cs=(4*(z/s)**2+1) **(0.5)-2*(z/s)
cs=numpy.array(cs)
return cs
def forward_model (sigma, depth, coil_spacing, coil_position):
global cs
global cond_true
global cond_apps
cond_true=numpy.array(sigma)
cond_apps=numpy.zeros(len(coil_spacing))
for i in range (0, len(coil_spacing)):
cs= Cumulative_Sensitivity (depth, coil_spacing[i], coil_position)
cond_app = sum(cond_true[:-1]*(cs[:-1]-cs[1:]))
cond_app = cond_app + cond_true[-1]*(cs[-1])
cond_apps[i] = cond_app
return cond_apps
# s1=30mS/m and s2=50mS/m, z=1m
sa_1=forward_model ([30, 50], [0, 1], [0.32], "hcp")
sa_2=forward_model ([30, 50], [0, 1], [0.71], "hcp")
sa_3=forward_model ([30, 50], [0, 1], [1.18], "hcp")
sa_4=forward_model ([30, 50], [0, 1], [0.32], "vcp")
sa_5=forward_model ([30, 50], [0, 1], [0.71], "vcp")
sa_6=forward_model ([30, 50], [0, 1], [1.18], "vcp")
data=numpy.array([sa_1, sa_2, sa_3, sa_4, sa_5, sa_6])
#
for i in range (10,110, 10):
for j in range (10,110, 10):
cond_HC1=forward_model ([j, i], [0, 1], [0.32], "hcp")
cond_HC2=forward_model ([j, i], [0, 1], [0.71], "hcp")
cond_HC3=forward_model ([j, i], [0, 1], [1.18], "hcp")
cond_VC1=forward_model ([j, i], [0, 1], [0.32], "vcp")
cond_VC2=forward_model ([j, i], [0, 1], [0.71], "vcp")
cond_VC3=forward_model ([j, i], [0, 1], [1.18], "vcp")
predicted=numpy.array([cond_HC1, cond_HC2, cond_HC3, cond_VC1, cond_VC2, cond_VC3])
rms=numpy.array(sqrt(sum((predicted - data)**2).mean()))
x = numpy.linspace(10,100,10)
y = numpy.linspace(10,100,10)
X,Y=numpy.meshgrid(x,y)
Z=rms
contour = plt.contour(X, Y, Z)import numpy
import matplotlib.pyplot as plt
from math import sqrt
def Cumulative_Sensitivity (depth, coil_spacing, coil_position):
global z
global s
z=numpy.array(depth)
s=numpy.array(coil_spacing)
if coil_position == "hcp":
cs=(4*(z/s)**2+1)**(-0.5)
cs=numpy.array(cs)
elif coil_position == "vcp":
cs=(4*(z/s)**2+1) **(0.5)-2*(z/s)
cs=numpy.array(cs)
return cs
def forward_model (sigma, depth, coil_spacing, coil_position):
global cs
global cond_true
global cond_apps
cond_true=numpy.array(sigma)
cond_apps=numpy.zeros(len(coil_spacing))
for i in range (0, len(coil_spacing)):
cs= Cumulative_Sensitivity (depth, coil_spacing[i], coil_position)
cond_app = sum(cond_true[:-1]*(cs[:-1]-cs[1:]))
cond_app = cond_app + cond_true[-1]*(cs[-1])
cond_apps[i] = cond_app
return cond_apps
# s1=30mS/m and s2=50mS/m, z=1m
sa_1=forward_model ([30, 50], [0, 1], [0.32], "hcp")
sa_2=forward_model ([30, 50], [0, 1], [0.71], "hcp")
sa_3=forward_model ([30, 50], [0, 1], [1.18], "hcp")
sa_4=forward_model ([30, 50], [0, 1], [0.32], "vcp")
sa_5=forward_model ([30, 50], [0, 1], [0.71], "vcp")
sa_6=forward_model ([30, 50], [0, 1], [1.18], "vcp")
data=numpy.array([sa_1, sa_2, sa_3, sa_4, sa_5, sa_6])
#
for i in range (10,110, 10):
for j in range (10,110, 10):
cond_HC1=forward_model ([j, i], [0, 1], [0.32], "hcp")
cond_HC2=forward_model ([j, i], [0, 1], [0.71], "hcp")
cond_HC3=forward_model ([j, i], [0, 1], [1.18], "hcp")
cond_VC1=forward_model ([j, i], [0, 1], [0.32], "vcp")
cond_VC2=forward_model ([j, i], [0, 1], [0.71], "vcp")
cond_VC3=forward_model ([j, i], [0, 1], [1.18], "vcp")
predicted=numpy.array([cond_HC1, cond_HC2, cond_HC3, cond_VC1, cond_VC2, cond_VC3])
rms=numpy.array(sqrt(sum((predicted - data)**2).mean()))
x = numpy.linspace(10,100,10)
y = numpy.linspace(10,100,10)
X,Y=numpy.meshgrid(x,y)
Z=rms
contour = plt.contour(X, Y, Z)import numpy
import matplotlib.pyplot as plt
from math import sqrt
def Cumulative_Sensitivity (depth, coil_spacing, coil_position):
global z
global s
z=numpy.array(depth)
s=numpy.array(coil_spacing)
if coil_position == "hcp":
cs=(4*(z/s)**2+1)**(-0.5)
cs=numpy.array(cs)
elif coil_position == "vcp":
cs=(4*(z/s)**2+1) **(0.5)-2*(z/s)
cs=numpy.array(cs)
return cs
def forward_model (sigma, depth, coil_spacing, coil_position):
global cs
global cond_true
global cond_apps
cond_true=numpy.array(sigma)
cond_apps=numpy.zeros(len(coil_spacing))
for i in range (0, len(coil_spacing)):
cs= Cumulative_Sensitivity (depth, coil_spacing[i], coil_position)
cond_app = sum(cond_true[:-1]*(cs[:-1]-cs[1:]))
cond_app = cond_app + cond_true[-1]*(cs[-1])
cond_apps[i] = cond_app
return cond_apps
# s1=30mS/m and s2=50mS/m, z=1m
sa_1=forward_model ([30, 50], [0, 1], [0.32], "hcp")
sa_2=forward_model ([30, 50], [0, 1], [0.71], "hcp")
sa_3=forward_model ([30, 50], [0, 1], [1.18], "hcp")
sa_4=forward_model ([30, 50], [0, 1], [0.32], "vcp")
sa_5=forward_model ([30, 50], [0, 1], [0.71], "vcp")
sa_6=forward_model ([30, 50], [0, 1], [1.18], "vcp")
data=numpy.array([sa_1, sa_2, sa_3, sa_4, sa_5, sa_6])
#
for i in range (10,110, 10):
for j in range (10,110, 10):
cond_HC1=forward_model ([j, i], [0, 1], [0.32], "hcp")
cond_HC2=forward_model ([j, i], [0, 1], [0.71], "hcp")
cond_HC3=forward_model ([j, i], [0, 1], [1.18], "hcp")
cond_VC1=forward_model ([j, i], [0, 1], [0.32], "vcp")
cond_VC2=forward_model ([j, i], [0, 1], [0.71], "vcp")
cond_VC3=forward_model ([j, i], [0, 1], [1.18], "vcp")
predicted=numpy.array([cond_HC1, cond_HC2, cond_HC3, cond_VC1, cond_VC2, cond_VC3])
rms=numpy.array(sqrt(sum((predicted - data)**2).mean()))
x = numpy.linspace(10,100,10)
y = numpy.linspace(10,100,10)
X,Y=numpy.meshgrid(x,y)
Z=rms
contour = plt.contour(X, Y, Z)python
python
edited Mar 26 at 9:11
Fatima
asked Mar 25 at 5:47
FatimaFatima
92 bronze badges
92 bronze badges
please show some code
– David Jones
Mar 25 at 8:59
add a comment |
please show some code
– David Jones
Mar 25 at 8:59
please show some code
– David Jones
Mar 25 at 8:59
please show some code
– David Jones
Mar 25 at 8: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%2f55331867%2fhow-to-draw-a-contour-plot-with-two-2d-array-x-y-and-0d-array-i-e-an-scalar%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%2f55331867%2fhow-to-draw-a-contour-plot-with-two-2d-array-x-y-and-0d-array-i-e-an-scalar%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
please show some code
– David Jones
Mar 25 at 8:59