Function to define an area in a colormap and return average pixel valueDefining the midpoint of a colormap in matplotlibDisplaying colormap only and hiding imshow area datapython matplotlib, get pixel value after colormap appliedhow to define colormap with absolute values with matplotlibHow to define a colormap in matplotlib using HSV colors?Opencv C++: Display pixel value using cursor of the image before applying colormapdisplay matrix values and colormapDefine a colormap for each set of values in an arrayPlotting a colormap in Python changes unexpectedly depending on the range of values plotted?How to anchor the value 0 in diverging colormap to the exactly the middle?

SOQL Not Recognizing Field?

Taxi Services at Didcot

Is it possible to have a wealthy country without middle class?

Motivation - or how can I get myself to do the work I know I need to?

SQL counting distinct over partition

Fixing obscure 8080 emulator bug?

What is the `some` keyword in SwiftUI?

What makes an item an artifact?

A curious prime counting approximation or just data overfitting?

How can I tell the difference between unmarked sugar and stevia?

Using "subway" as name for London Underground?

Second (easy access) account in case my bank screws up

Did Milano or Benatar approve or comment on their namesake MCU ships?

Compiling C files on Ubuntu and using the executable on Windows

Why didn't Voldemort recognize that Dumbledore was affected by his curse?

What makes Ada the language of choice for the ISS's safety-critical systems?

What ways have you found to get edits from non-LaTeX users?

SHELL environment variable still points to zsh after using bash

How to hide an urban landmark?

Medieval flying castle propulsion

How can electric fields be used to detect cracks in metals?

What is the highest possible temporary AC at level 1, without any help from others?

Does the spell Clone require any material components to cast on a Zealot barbarian?

Thread Pool C++ Implementation



Function to define an area in a colormap and return average pixel value


Defining the midpoint of a colormap in matplotlibDisplaying colormap only and hiding imshow area datapython matplotlib, get pixel value after colormap appliedhow to define colormap with absolute values with matplotlibHow to define a colormap in matplotlib using HSV colors?Opencv C++: Display pixel value using cursor of the image before applying colormapdisplay matrix values and colormapDefine a colormap for each set of values in an arrayPlotting a colormap in Python changes unexpectedly depending on the range of values plotted?How to anchor the value 0 in diverging colormap to the exactly the middle?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a .txt of delimited data, about 600 x 600 cells in size. I have graphed it using matplotlib's imshow and now I want to analyze a specific part of interest in it. Particularly, I'm interested in drawing a defined region around a specific (x, y) point and returning the average value (from the file) within that region. I've done some searching but I can't find anything that will let me manipulate this as such. The closest thing I've come to is patches or the patches.Circle function, but all that does is let me draw a circle around the defined point. I can't extract (or can't figure out how to) any information from there. Here is my working example:



import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches

#Setup Plots
fig, ax = plt.subplots(figsize=(20, 10))
plt.rcParams.update('font.size': 20)
#Open Data
filename = "smalltest.txt"
data = np.genfromtxt(filename, delimiter = ";", skip_header = 0)

#Colourmap
ax.imshow(data, cmap ='hot', interpolation='nearest')

#-------------------------------------
#Average values around point

#Create circle
circ = patches.Circle((345, 195), 60, alpha=0.8, fc='none',
edgecolor = 'yellow')
ax.add_patch(circ)

fig.colorbar(ax.imshow(data, cmap ='hot', interpolation='nearest'),
label = "Temperature (K)")
plt.show()


Here is a picture as an example:
Graph produced. Trying to get average value within the circle that is drawn










share|improve this question






















  • To draw a static circle, patches.Circle is fine; to let the user draw a circle interactively, you can use an EllipseSelector. To get the data from an array the lies within a range of coordinates you can create a numpy.meshgrid of the coordinates and filter the data by a condition on the coordinates. e.g. filtered_data = data[(x-x0)**2 + (y-y0)**2 y <= r**2]. To calculate a mean of an array, use array.mean().

    – ImportanceOfBeingErnest
    Mar 24 at 19:06











  • @ImportanceOfBeingErnest Looks like numpy.meshgrid is what I was looking for. Thank you very much!

    – mathwiz97
    Mar 24 at 20:17


















0















I have a .txt of delimited data, about 600 x 600 cells in size. I have graphed it using matplotlib's imshow and now I want to analyze a specific part of interest in it. Particularly, I'm interested in drawing a defined region around a specific (x, y) point and returning the average value (from the file) within that region. I've done some searching but I can't find anything that will let me manipulate this as such. The closest thing I've come to is patches or the patches.Circle function, but all that does is let me draw a circle around the defined point. I can't extract (or can't figure out how to) any information from there. Here is my working example:



import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches

#Setup Plots
fig, ax = plt.subplots(figsize=(20, 10))
plt.rcParams.update('font.size': 20)
#Open Data
filename = "smalltest.txt"
data = np.genfromtxt(filename, delimiter = ";", skip_header = 0)

#Colourmap
ax.imshow(data, cmap ='hot', interpolation='nearest')

#-------------------------------------
#Average values around point

#Create circle
circ = patches.Circle((345, 195), 60, alpha=0.8, fc='none',
edgecolor = 'yellow')
ax.add_patch(circ)

fig.colorbar(ax.imshow(data, cmap ='hot', interpolation='nearest'),
label = "Temperature (K)")
plt.show()


Here is a picture as an example:
Graph produced. Trying to get average value within the circle that is drawn










share|improve this question






















  • To draw a static circle, patches.Circle is fine; to let the user draw a circle interactively, you can use an EllipseSelector. To get the data from an array the lies within a range of coordinates you can create a numpy.meshgrid of the coordinates and filter the data by a condition on the coordinates. e.g. filtered_data = data[(x-x0)**2 + (y-y0)**2 y <= r**2]. To calculate a mean of an array, use array.mean().

    – ImportanceOfBeingErnest
    Mar 24 at 19:06











  • @ImportanceOfBeingErnest Looks like numpy.meshgrid is what I was looking for. Thank you very much!

    – mathwiz97
    Mar 24 at 20:17














0












0








0








I have a .txt of delimited data, about 600 x 600 cells in size. I have graphed it using matplotlib's imshow and now I want to analyze a specific part of interest in it. Particularly, I'm interested in drawing a defined region around a specific (x, y) point and returning the average value (from the file) within that region. I've done some searching but I can't find anything that will let me manipulate this as such. The closest thing I've come to is patches or the patches.Circle function, but all that does is let me draw a circle around the defined point. I can't extract (or can't figure out how to) any information from there. Here is my working example:



import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches

#Setup Plots
fig, ax = plt.subplots(figsize=(20, 10))
plt.rcParams.update('font.size': 20)
#Open Data
filename = "smalltest.txt"
data = np.genfromtxt(filename, delimiter = ";", skip_header = 0)

#Colourmap
ax.imshow(data, cmap ='hot', interpolation='nearest')

#-------------------------------------
#Average values around point

#Create circle
circ = patches.Circle((345, 195), 60, alpha=0.8, fc='none',
edgecolor = 'yellow')
ax.add_patch(circ)

fig.colorbar(ax.imshow(data, cmap ='hot', interpolation='nearest'),
label = "Temperature (K)")
plt.show()


Here is a picture as an example:
Graph produced. Trying to get average value within the circle that is drawn










share|improve this question














I have a .txt of delimited data, about 600 x 600 cells in size. I have graphed it using matplotlib's imshow and now I want to analyze a specific part of interest in it. Particularly, I'm interested in drawing a defined region around a specific (x, y) point and returning the average value (from the file) within that region. I've done some searching but I can't find anything that will let me manipulate this as such. The closest thing I've come to is patches or the patches.Circle function, but all that does is let me draw a circle around the defined point. I can't extract (or can't figure out how to) any information from there. Here is my working example:



import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches

#Setup Plots
fig, ax = plt.subplots(figsize=(20, 10))
plt.rcParams.update('font.size': 20)
#Open Data
filename = "smalltest.txt"
data = np.genfromtxt(filename, delimiter = ";", skip_header = 0)

#Colourmap
ax.imshow(data, cmap ='hot', interpolation='nearest')

#-------------------------------------
#Average values around point

#Create circle
circ = patches.Circle((345, 195), 60, alpha=0.8, fc='none',
edgecolor = 'yellow')
ax.add_patch(circ)

fig.colorbar(ax.imshow(data, cmap ='hot', interpolation='nearest'),
label = "Temperature (K)")
plt.show()


Here is a picture as an example:
Graph produced. Trying to get average value within the circle that is drawn







matplotlib colormap imshow






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 24 at 17:02









mathwiz97mathwiz97

174




174












  • To draw a static circle, patches.Circle is fine; to let the user draw a circle interactively, you can use an EllipseSelector. To get the data from an array the lies within a range of coordinates you can create a numpy.meshgrid of the coordinates and filter the data by a condition on the coordinates. e.g. filtered_data = data[(x-x0)**2 + (y-y0)**2 y <= r**2]. To calculate a mean of an array, use array.mean().

    – ImportanceOfBeingErnest
    Mar 24 at 19:06











  • @ImportanceOfBeingErnest Looks like numpy.meshgrid is what I was looking for. Thank you very much!

    – mathwiz97
    Mar 24 at 20:17


















  • To draw a static circle, patches.Circle is fine; to let the user draw a circle interactively, you can use an EllipseSelector. To get the data from an array the lies within a range of coordinates you can create a numpy.meshgrid of the coordinates and filter the data by a condition on the coordinates. e.g. filtered_data = data[(x-x0)**2 + (y-y0)**2 y <= r**2]. To calculate a mean of an array, use array.mean().

    – ImportanceOfBeingErnest
    Mar 24 at 19:06











  • @ImportanceOfBeingErnest Looks like numpy.meshgrid is what I was looking for. Thank you very much!

    – mathwiz97
    Mar 24 at 20:17

















To draw a static circle, patches.Circle is fine; to let the user draw a circle interactively, you can use an EllipseSelector. To get the data from an array the lies within a range of coordinates you can create a numpy.meshgrid of the coordinates and filter the data by a condition on the coordinates. e.g. filtered_data = data[(x-x0)**2 + (y-y0)**2 y <= r**2]. To calculate a mean of an array, use array.mean().

– ImportanceOfBeingErnest
Mar 24 at 19:06





To draw a static circle, patches.Circle is fine; to let the user draw a circle interactively, you can use an EllipseSelector. To get the data from an array the lies within a range of coordinates you can create a numpy.meshgrid of the coordinates and filter the data by a condition on the coordinates. e.g. filtered_data = data[(x-x0)**2 + (y-y0)**2 y <= r**2]. To calculate a mean of an array, use array.mean().

– ImportanceOfBeingErnest
Mar 24 at 19:06













@ImportanceOfBeingErnest Looks like numpy.meshgrid is what I was looking for. Thank you very much!

– mathwiz97
Mar 24 at 20:17






@ImportanceOfBeingErnest Looks like numpy.meshgrid is what I was looking for. Thank you very much!

– mathwiz97
Mar 24 at 20:17













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%2f55326286%2ffunction-to-define-an-area-in-a-colormap-and-return-average-pixel-value%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%2f55326286%2ffunction-to-define-an-area-in-a-colormap-and-return-average-pixel-value%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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript