Polar histogram in Python for given r, theta and z values The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceCalling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?How to get the current time in PythonHow do I sort a dictionary by value?Check if a given key already exists in a dictionaryDoes Python have a string 'contains' substring method?
How to stretch delimiters to envolve matrices inside of a kbordermatrix?
Segmentation fault output is suppressed when piping stdin into a function. Why?
Can a relay be on for 16 hours continuously?
How is simplicity better than precision and clarity in prose?
Typeface like Times New Roman but with "tied" percent sign
How to remove this toilet supply line that seems to have no nut?
Does Parliament hold absolute power in the UK?
The following signatures were invalid: EXPKEYSIG 1397BC53640DB551
Is above average number of years spent on PhD considered a red flag in future academia or industry positions?
Create an outline of font
"... to apply for a visa" or "... and applied for a visa"?
What do you call a plan that's an alternative plan in case your initial plan fails?
What is this lever in Argentinian toilets?
How many people can fit inside Mordenkainen's Magnificent Mansion?
Arduino Pro Micro - switch off LEDs
Why can't wing-mounted spoilers be used to steepen approaches?
Can undead you have reanimated wait inside a portable hole?
What can I do if neighbor is blocking my solar panels intentionally?
How do I add random spotting to the same face in cycles?
First use of “packing” as in carrying a gun
Working through the single responsibility principle (SRP) in Python when calls are expensive
Change bounding box of math glyphs in LuaTeX
Who or what is the being for whom Being is a question for Heidegger?
Can a 1st-level character have an ability score above 18?
Polar histogram in Python for given r, theta and z values
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceCalling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?How to get the current time in PythonHow do I sort a dictionary by value?Check if a given key already exists in a dictionaryDoes Python have a string 'contains' substring method?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a dataframe consisting of measurements from a particular magnetometer station over time, with columns corresponding to:
- its latitude (which I think of as a radius)
- its azimuthal angle
- a measured quantity at this specific time
I was wondering of a way to plot this dataframe as a polar histogram for the measured variable: ie something like this:
I have looked at the special histogram in physt
but this allows me to only put in x,y values and I'm quite confused by it all.
Could anybody help?
python matplotlib polar-coordinates
|
show 1 more comment
I have a dataframe consisting of measurements from a particular magnetometer station over time, with columns corresponding to:
- its latitude (which I think of as a radius)
- its azimuthal angle
- a measured quantity at this specific time
I was wondering of a way to plot this dataframe as a polar histogram for the measured variable: ie something like this:
I have looked at the special histogram in physt
but this allows me to only put in x,y values and I'm quite confused by it all.
Could anybody help?
python matplotlib polar-coordinates
Just wanted to say that is a very cool chart
– rgk
Mar 8 at 13:38
Seconding on the cool chart. The closest I've ever encountered is matplotlib.org/basemap/users/paeqd.html but I'm not sure it can be stretched for this kind of output
– roganjosh
Mar 8 at 13:39
Are you sure you want a histogram? That seems to contradict the third requirement "a measured quantity at this specific time". Can you clarify what exactly you need?
– ImportanceOfBeingErnest
Mar 8 at 13:53
Essential what I want to show is a certain characteristic of the measured quantity at a specific radius-azimuth bin. So with histogram what I mean is an occurrence number in the specific radius-azimuth bin. Does that help?
– R Thompson
Mar 8 at 14:20
No, it doesn't. It's easy: Do you have 2 columns,radius
andazimut
? Then you can plot occurance as histogram. Do you have 3 columns,radius
andazimut
,measured quantity
, then you cannot plot a histogram, but rather themeasured quantity
as a function of the other two. Which one is it?
– ImportanceOfBeingErnest
Mar 8 at 17:16
|
show 1 more comment
I have a dataframe consisting of measurements from a particular magnetometer station over time, with columns corresponding to:
- its latitude (which I think of as a radius)
- its azimuthal angle
- a measured quantity at this specific time
I was wondering of a way to plot this dataframe as a polar histogram for the measured variable: ie something like this:
I have looked at the special histogram in physt
but this allows me to only put in x,y values and I'm quite confused by it all.
Could anybody help?
python matplotlib polar-coordinates
I have a dataframe consisting of measurements from a particular magnetometer station over time, with columns corresponding to:
- its latitude (which I think of as a radius)
- its azimuthal angle
- a measured quantity at this specific time
I was wondering of a way to plot this dataframe as a polar histogram for the measured variable: ie something like this:
I have looked at the special histogram in physt
but this allows me to only put in x,y values and I'm quite confused by it all.
Could anybody help?
python matplotlib polar-coordinates
python matplotlib polar-coordinates
edited Mar 8 at 13:38
R Thompson
asked Mar 8 at 13:35
R ThompsonR Thompson
7318
7318
Just wanted to say that is a very cool chart
– rgk
Mar 8 at 13:38
Seconding on the cool chart. The closest I've ever encountered is matplotlib.org/basemap/users/paeqd.html but I'm not sure it can be stretched for this kind of output
– roganjosh
Mar 8 at 13:39
Are you sure you want a histogram? That seems to contradict the third requirement "a measured quantity at this specific time". Can you clarify what exactly you need?
– ImportanceOfBeingErnest
Mar 8 at 13:53
Essential what I want to show is a certain characteristic of the measured quantity at a specific radius-azimuth bin. So with histogram what I mean is an occurrence number in the specific radius-azimuth bin. Does that help?
– R Thompson
Mar 8 at 14:20
No, it doesn't. It's easy: Do you have 2 columns,radius
andazimut
? Then you can plot occurance as histogram. Do you have 3 columns,radius
andazimut
,measured quantity
, then you cannot plot a histogram, but rather themeasured quantity
as a function of the other two. Which one is it?
– ImportanceOfBeingErnest
Mar 8 at 17:16
|
show 1 more comment
Just wanted to say that is a very cool chart
– rgk
Mar 8 at 13:38
Seconding on the cool chart. The closest I've ever encountered is matplotlib.org/basemap/users/paeqd.html but I'm not sure it can be stretched for this kind of output
– roganjosh
Mar 8 at 13:39
Are you sure you want a histogram? That seems to contradict the third requirement "a measured quantity at this specific time". Can you clarify what exactly you need?
– ImportanceOfBeingErnest
Mar 8 at 13:53
Essential what I want to show is a certain characteristic of the measured quantity at a specific radius-azimuth bin. So with histogram what I mean is an occurrence number in the specific radius-azimuth bin. Does that help?
– R Thompson
Mar 8 at 14:20
No, it doesn't. It's easy: Do you have 2 columns,radius
andazimut
? Then you can plot occurance as histogram. Do you have 3 columns,radius
andazimut
,measured quantity
, then you cannot plot a histogram, but rather themeasured quantity
as a function of the other two. Which one is it?
– ImportanceOfBeingErnest
Mar 8 at 17:16
Just wanted to say that is a very cool chart
– rgk
Mar 8 at 13:38
Just wanted to say that is a very cool chart
– rgk
Mar 8 at 13:38
Seconding on the cool chart. The closest I've ever encountered is matplotlib.org/basemap/users/paeqd.html but I'm not sure it can be stretched for this kind of output
– roganjosh
Mar 8 at 13:39
Seconding on the cool chart. The closest I've ever encountered is matplotlib.org/basemap/users/paeqd.html but I'm not sure it can be stretched for this kind of output
– roganjosh
Mar 8 at 13:39
Are you sure you want a histogram? That seems to contradict the third requirement "a measured quantity at this specific time". Can you clarify what exactly you need?
– ImportanceOfBeingErnest
Mar 8 at 13:53
Are you sure you want a histogram? That seems to contradict the third requirement "a measured quantity at this specific time". Can you clarify what exactly you need?
– ImportanceOfBeingErnest
Mar 8 at 13:53
Essential what I want to show is a certain characteristic of the measured quantity at a specific radius-azimuth bin. So with histogram what I mean is an occurrence number in the specific radius-azimuth bin. Does that help?
– R Thompson
Mar 8 at 14:20
Essential what I want to show is a certain characteristic of the measured quantity at a specific radius-azimuth bin. So with histogram what I mean is an occurrence number in the specific radius-azimuth bin. Does that help?
– R Thompson
Mar 8 at 14:20
No, it doesn't. It's easy: Do you have 2 columns,
radius
and azimut
? Then you can plot occurance as histogram. Do you have 3 columns, radius
and azimut
, measured quantity
, then you cannot plot a histogram, but rather the measured quantity
as a function of the other two. Which one is it?– ImportanceOfBeingErnest
Mar 8 at 17:16
No, it doesn't. It's easy: Do you have 2 columns,
radius
and azimut
? Then you can plot occurance as histogram. Do you have 3 columns, radius
and azimut
, measured quantity
, then you cannot plot a histogram, but rather the measured quantity
as a function of the other two. Which one is it?– ImportanceOfBeingErnest
Mar 8 at 17:16
|
show 1 more comment
3 Answers
3
active
oldest
votes
Calculating a histogram is easily done with numpy.histogram2d
. Plotting the resulting 2D array can be done with matplotlib's pcolormesh
.
import numpy as np; np.random.seed(42)
import matplotlib.pyplot as plt
# two input arrays
azimut = np.random.rand(3000)*2*np.pi
radius = np.random.rayleigh(29, size=3000)
# define binning
rbins = np.linspace(0,radius.max(), 30)
abins = np.linspace(0,2*np.pi, 60)
#calculate histogram
hist, _, _ = np.histogram2d(azimut, radius, bins=(abins, rbins))
A, R = np.meshgrid(abins, rbins)
# plot
fig, ax = plt.subplots(subplot_kw=dict(projection="polar"))
pc = ax.pcolormesh(A, R, hist.T, cmap="magma_r")
fig.colorbar(pc)
plt.show()
Thanks this was exactly what I wanted!
– R Thompson
Mar 8 at 18:48
add a comment |
This appears to be what you're looking for: https://physt.readthedocs.io/en/latest/special_histograms.html#Polar-histogram
from physt import histogram, binnings, special
import numpy as np
import matplotlib.pyplot as plt
# Generate some points in the Cartesian coordinates
np.random.seed(42)
x = np.random.rand(1000)
y = np.random.rand(1000)
z = np.random.rand(1000)
# Create a polar histogram with default parameters
hist = special.polar_histogram(x, y)
ax = hist.plot.polar_map()
The docs linked include more examples with colors, bin sizing etc.
Edit: I think this is going to take a bit of munging to get your data into the right shape, but I think this example illustrates the library's capabilities and can be adjusted to your use case:
import random
import numpy as np
import matplotlib.pyplot as plt
from physt import special
# Generate some points in the Cartesian coordinates
np.random.seed(42)
gen = lambda l, h, s = 3000: np.asarray([random.random() * (h - l) + l for _ in range(s)])
X = gen(-100, 100)
Y = gen(-1000, 1000)
Z = gen(0, 1400)
hist = special.polar_histogram(X, Y, weights=Z, radial_bins=40)
# ax = hist.plot.polar_map()
hist.plot.polar_map(density=True, show_zero=False, cmap="inferno", lw=0.5, figsize=(5, 5))
plt.show()
This is what I originally tried, but it doesn't allow for any z information as far as I could figure out
– R Thompson
Mar 8 at 13:40
z information as in magnitude? Isn't that just the values in the data? Forgive me if I'm not fully understanding your question
– rgk
Mar 8 at 13:44
I guess for now the values in the data of the measured quantity might not be the most relevant. So forget that apart for now. So I have effectively a time series for r and theta, how would I put that into the function above to get the histogram over the whole azimuthal space?
– R Thompson
Mar 8 at 13:54
Edited my example above - the package receives X & Y as cartesian coordinates, and your polar coodinate data can be transformed to fit the function and produce the chart you want (see more: math.uh.edu/~mmsosa/Math1330/Calendar/1330Day28.pdf). I used extreme values for Y to illustrate the point, but symmetrically scaled X & Y inputs would produce a radially symmetric chart.
– rgk
Mar 8 at 15:05
add a comment |
This is not the full answer but you could find some ideas hear :
https://github.com/TronSkywalker/Visuals/blob/master/Circular_bar_charts.py
let me know how far you came!:)
Technically you would need to replace the zip(..)-loop with a double for-loop over r and the angles. The colors can be intuitively coupled more or less to your z direction.
– Richard Lenkiewicz
Mar 8 at 13:45
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%2f55064339%2fpolar-histogram-in-python-for-given-r-theta-and-z-values%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Calculating a histogram is easily done with numpy.histogram2d
. Plotting the resulting 2D array can be done with matplotlib's pcolormesh
.
import numpy as np; np.random.seed(42)
import matplotlib.pyplot as plt
# two input arrays
azimut = np.random.rand(3000)*2*np.pi
radius = np.random.rayleigh(29, size=3000)
# define binning
rbins = np.linspace(0,radius.max(), 30)
abins = np.linspace(0,2*np.pi, 60)
#calculate histogram
hist, _, _ = np.histogram2d(azimut, radius, bins=(abins, rbins))
A, R = np.meshgrid(abins, rbins)
# plot
fig, ax = plt.subplots(subplot_kw=dict(projection="polar"))
pc = ax.pcolormesh(A, R, hist.T, cmap="magma_r")
fig.colorbar(pc)
plt.show()
Thanks this was exactly what I wanted!
– R Thompson
Mar 8 at 18:48
add a comment |
Calculating a histogram is easily done with numpy.histogram2d
. Plotting the resulting 2D array can be done with matplotlib's pcolormesh
.
import numpy as np; np.random.seed(42)
import matplotlib.pyplot as plt
# two input arrays
azimut = np.random.rand(3000)*2*np.pi
radius = np.random.rayleigh(29, size=3000)
# define binning
rbins = np.linspace(0,radius.max(), 30)
abins = np.linspace(0,2*np.pi, 60)
#calculate histogram
hist, _, _ = np.histogram2d(azimut, radius, bins=(abins, rbins))
A, R = np.meshgrid(abins, rbins)
# plot
fig, ax = plt.subplots(subplot_kw=dict(projection="polar"))
pc = ax.pcolormesh(A, R, hist.T, cmap="magma_r")
fig.colorbar(pc)
plt.show()
Thanks this was exactly what I wanted!
– R Thompson
Mar 8 at 18:48
add a comment |
Calculating a histogram is easily done with numpy.histogram2d
. Plotting the resulting 2D array can be done with matplotlib's pcolormesh
.
import numpy as np; np.random.seed(42)
import matplotlib.pyplot as plt
# two input arrays
azimut = np.random.rand(3000)*2*np.pi
radius = np.random.rayleigh(29, size=3000)
# define binning
rbins = np.linspace(0,radius.max(), 30)
abins = np.linspace(0,2*np.pi, 60)
#calculate histogram
hist, _, _ = np.histogram2d(azimut, radius, bins=(abins, rbins))
A, R = np.meshgrid(abins, rbins)
# plot
fig, ax = plt.subplots(subplot_kw=dict(projection="polar"))
pc = ax.pcolormesh(A, R, hist.T, cmap="magma_r")
fig.colorbar(pc)
plt.show()
Calculating a histogram is easily done with numpy.histogram2d
. Plotting the resulting 2D array can be done with matplotlib's pcolormesh
.
import numpy as np; np.random.seed(42)
import matplotlib.pyplot as plt
# two input arrays
azimut = np.random.rand(3000)*2*np.pi
radius = np.random.rayleigh(29, size=3000)
# define binning
rbins = np.linspace(0,radius.max(), 30)
abins = np.linspace(0,2*np.pi, 60)
#calculate histogram
hist, _, _ = np.histogram2d(azimut, radius, bins=(abins, rbins))
A, R = np.meshgrid(abins, rbins)
# plot
fig, ax = plt.subplots(subplot_kw=dict(projection="polar"))
pc = ax.pcolormesh(A, R, hist.T, cmap="magma_r")
fig.colorbar(pc)
plt.show()
answered Mar 8 at 17:46
ImportanceOfBeingErnestImportanceOfBeingErnest
142k13169248
142k13169248
Thanks this was exactly what I wanted!
– R Thompson
Mar 8 at 18:48
add a comment |
Thanks this was exactly what I wanted!
– R Thompson
Mar 8 at 18:48
Thanks this was exactly what I wanted!
– R Thompson
Mar 8 at 18:48
Thanks this was exactly what I wanted!
– R Thompson
Mar 8 at 18:48
add a comment |
This appears to be what you're looking for: https://physt.readthedocs.io/en/latest/special_histograms.html#Polar-histogram
from physt import histogram, binnings, special
import numpy as np
import matplotlib.pyplot as plt
# Generate some points in the Cartesian coordinates
np.random.seed(42)
x = np.random.rand(1000)
y = np.random.rand(1000)
z = np.random.rand(1000)
# Create a polar histogram with default parameters
hist = special.polar_histogram(x, y)
ax = hist.plot.polar_map()
The docs linked include more examples with colors, bin sizing etc.
Edit: I think this is going to take a bit of munging to get your data into the right shape, but I think this example illustrates the library's capabilities and can be adjusted to your use case:
import random
import numpy as np
import matplotlib.pyplot as plt
from physt import special
# Generate some points in the Cartesian coordinates
np.random.seed(42)
gen = lambda l, h, s = 3000: np.asarray([random.random() * (h - l) + l for _ in range(s)])
X = gen(-100, 100)
Y = gen(-1000, 1000)
Z = gen(0, 1400)
hist = special.polar_histogram(X, Y, weights=Z, radial_bins=40)
# ax = hist.plot.polar_map()
hist.plot.polar_map(density=True, show_zero=False, cmap="inferno", lw=0.5, figsize=(5, 5))
plt.show()
This is what I originally tried, but it doesn't allow for any z information as far as I could figure out
– R Thompson
Mar 8 at 13:40
z information as in magnitude? Isn't that just the values in the data? Forgive me if I'm not fully understanding your question
– rgk
Mar 8 at 13:44
I guess for now the values in the data of the measured quantity might not be the most relevant. So forget that apart for now. So I have effectively a time series for r and theta, how would I put that into the function above to get the histogram over the whole azimuthal space?
– R Thompson
Mar 8 at 13:54
Edited my example above - the package receives X & Y as cartesian coordinates, and your polar coodinate data can be transformed to fit the function and produce the chart you want (see more: math.uh.edu/~mmsosa/Math1330/Calendar/1330Day28.pdf). I used extreme values for Y to illustrate the point, but symmetrically scaled X & Y inputs would produce a radially symmetric chart.
– rgk
Mar 8 at 15:05
add a comment |
This appears to be what you're looking for: https://physt.readthedocs.io/en/latest/special_histograms.html#Polar-histogram
from physt import histogram, binnings, special
import numpy as np
import matplotlib.pyplot as plt
# Generate some points in the Cartesian coordinates
np.random.seed(42)
x = np.random.rand(1000)
y = np.random.rand(1000)
z = np.random.rand(1000)
# Create a polar histogram with default parameters
hist = special.polar_histogram(x, y)
ax = hist.plot.polar_map()
The docs linked include more examples with colors, bin sizing etc.
Edit: I think this is going to take a bit of munging to get your data into the right shape, but I think this example illustrates the library's capabilities and can be adjusted to your use case:
import random
import numpy as np
import matplotlib.pyplot as plt
from physt import special
# Generate some points in the Cartesian coordinates
np.random.seed(42)
gen = lambda l, h, s = 3000: np.asarray([random.random() * (h - l) + l for _ in range(s)])
X = gen(-100, 100)
Y = gen(-1000, 1000)
Z = gen(0, 1400)
hist = special.polar_histogram(X, Y, weights=Z, radial_bins=40)
# ax = hist.plot.polar_map()
hist.plot.polar_map(density=True, show_zero=False, cmap="inferno", lw=0.5, figsize=(5, 5))
plt.show()
This is what I originally tried, but it doesn't allow for any z information as far as I could figure out
– R Thompson
Mar 8 at 13:40
z information as in magnitude? Isn't that just the values in the data? Forgive me if I'm not fully understanding your question
– rgk
Mar 8 at 13:44
I guess for now the values in the data of the measured quantity might not be the most relevant. So forget that apart for now. So I have effectively a time series for r and theta, how would I put that into the function above to get the histogram over the whole azimuthal space?
– R Thompson
Mar 8 at 13:54
Edited my example above - the package receives X & Y as cartesian coordinates, and your polar coodinate data can be transformed to fit the function and produce the chart you want (see more: math.uh.edu/~mmsosa/Math1330/Calendar/1330Day28.pdf). I used extreme values for Y to illustrate the point, but symmetrically scaled X & Y inputs would produce a radially symmetric chart.
– rgk
Mar 8 at 15:05
add a comment |
This appears to be what you're looking for: https://physt.readthedocs.io/en/latest/special_histograms.html#Polar-histogram
from physt import histogram, binnings, special
import numpy as np
import matplotlib.pyplot as plt
# Generate some points in the Cartesian coordinates
np.random.seed(42)
x = np.random.rand(1000)
y = np.random.rand(1000)
z = np.random.rand(1000)
# Create a polar histogram with default parameters
hist = special.polar_histogram(x, y)
ax = hist.plot.polar_map()
The docs linked include more examples with colors, bin sizing etc.
Edit: I think this is going to take a bit of munging to get your data into the right shape, but I think this example illustrates the library's capabilities and can be adjusted to your use case:
import random
import numpy as np
import matplotlib.pyplot as plt
from physt import special
# Generate some points in the Cartesian coordinates
np.random.seed(42)
gen = lambda l, h, s = 3000: np.asarray([random.random() * (h - l) + l for _ in range(s)])
X = gen(-100, 100)
Y = gen(-1000, 1000)
Z = gen(0, 1400)
hist = special.polar_histogram(X, Y, weights=Z, radial_bins=40)
# ax = hist.plot.polar_map()
hist.plot.polar_map(density=True, show_zero=False, cmap="inferno", lw=0.5, figsize=(5, 5))
plt.show()
This appears to be what you're looking for: https://physt.readthedocs.io/en/latest/special_histograms.html#Polar-histogram
from physt import histogram, binnings, special
import numpy as np
import matplotlib.pyplot as plt
# Generate some points in the Cartesian coordinates
np.random.seed(42)
x = np.random.rand(1000)
y = np.random.rand(1000)
z = np.random.rand(1000)
# Create a polar histogram with default parameters
hist = special.polar_histogram(x, y)
ax = hist.plot.polar_map()
The docs linked include more examples with colors, bin sizing etc.
Edit: I think this is going to take a bit of munging to get your data into the right shape, but I think this example illustrates the library's capabilities and can be adjusted to your use case:
import random
import numpy as np
import matplotlib.pyplot as plt
from physt import special
# Generate some points in the Cartesian coordinates
np.random.seed(42)
gen = lambda l, h, s = 3000: np.asarray([random.random() * (h - l) + l for _ in range(s)])
X = gen(-100, 100)
Y = gen(-1000, 1000)
Z = gen(0, 1400)
hist = special.polar_histogram(X, Y, weights=Z, radial_bins=40)
# ax = hist.plot.polar_map()
hist.plot.polar_map(density=True, show_zero=False, cmap="inferno", lw=0.5, figsize=(5, 5))
plt.show()
edited Mar 8 at 14:57
answered Mar 8 at 13:39
rgkrgk
420510
420510
This is what I originally tried, but it doesn't allow for any z information as far as I could figure out
– R Thompson
Mar 8 at 13:40
z information as in magnitude? Isn't that just the values in the data? Forgive me if I'm not fully understanding your question
– rgk
Mar 8 at 13:44
I guess for now the values in the data of the measured quantity might not be the most relevant. So forget that apart for now. So I have effectively a time series for r and theta, how would I put that into the function above to get the histogram over the whole azimuthal space?
– R Thompson
Mar 8 at 13:54
Edited my example above - the package receives X & Y as cartesian coordinates, and your polar coodinate data can be transformed to fit the function and produce the chart you want (see more: math.uh.edu/~mmsosa/Math1330/Calendar/1330Day28.pdf). I used extreme values for Y to illustrate the point, but symmetrically scaled X & Y inputs would produce a radially symmetric chart.
– rgk
Mar 8 at 15:05
add a comment |
This is what I originally tried, but it doesn't allow for any z information as far as I could figure out
– R Thompson
Mar 8 at 13:40
z information as in magnitude? Isn't that just the values in the data? Forgive me if I'm not fully understanding your question
– rgk
Mar 8 at 13:44
I guess for now the values in the data of the measured quantity might not be the most relevant. So forget that apart for now. So I have effectively a time series for r and theta, how would I put that into the function above to get the histogram over the whole azimuthal space?
– R Thompson
Mar 8 at 13:54
Edited my example above - the package receives X & Y as cartesian coordinates, and your polar coodinate data can be transformed to fit the function and produce the chart you want (see more: math.uh.edu/~mmsosa/Math1330/Calendar/1330Day28.pdf). I used extreme values for Y to illustrate the point, but symmetrically scaled X & Y inputs would produce a radially symmetric chart.
– rgk
Mar 8 at 15:05
This is what I originally tried, but it doesn't allow for any z information as far as I could figure out
– R Thompson
Mar 8 at 13:40
This is what I originally tried, but it doesn't allow for any z information as far as I could figure out
– R Thompson
Mar 8 at 13:40
z information as in magnitude? Isn't that just the values in the data? Forgive me if I'm not fully understanding your question
– rgk
Mar 8 at 13:44
z information as in magnitude? Isn't that just the values in the data? Forgive me if I'm not fully understanding your question
– rgk
Mar 8 at 13:44
I guess for now the values in the data of the measured quantity might not be the most relevant. So forget that apart for now. So I have effectively a time series for r and theta, how would I put that into the function above to get the histogram over the whole azimuthal space?
– R Thompson
Mar 8 at 13:54
I guess for now the values in the data of the measured quantity might not be the most relevant. So forget that apart for now. So I have effectively a time series for r and theta, how would I put that into the function above to get the histogram over the whole azimuthal space?
– R Thompson
Mar 8 at 13:54
Edited my example above - the package receives X & Y as cartesian coordinates, and your polar coodinate data can be transformed to fit the function and produce the chart you want (see more: math.uh.edu/~mmsosa/Math1330/Calendar/1330Day28.pdf). I used extreme values for Y to illustrate the point, but symmetrically scaled X & Y inputs would produce a radially symmetric chart.
– rgk
Mar 8 at 15:05
Edited my example above - the package receives X & Y as cartesian coordinates, and your polar coodinate data can be transformed to fit the function and produce the chart you want (see more: math.uh.edu/~mmsosa/Math1330/Calendar/1330Day28.pdf). I used extreme values for Y to illustrate the point, but symmetrically scaled X & Y inputs would produce a radially symmetric chart.
– rgk
Mar 8 at 15:05
add a comment |
This is not the full answer but you could find some ideas hear :
https://github.com/TronSkywalker/Visuals/blob/master/Circular_bar_charts.py
let me know how far you came!:)
Technically you would need to replace the zip(..)-loop with a double for-loop over r and the angles. The colors can be intuitively coupled more or less to your z direction.
– Richard Lenkiewicz
Mar 8 at 13:45
add a comment |
This is not the full answer but you could find some ideas hear :
https://github.com/TronSkywalker/Visuals/blob/master/Circular_bar_charts.py
let me know how far you came!:)
Technically you would need to replace the zip(..)-loop with a double for-loop over r and the angles. The colors can be intuitively coupled more or less to your z direction.
– Richard Lenkiewicz
Mar 8 at 13:45
add a comment |
This is not the full answer but you could find some ideas hear :
https://github.com/TronSkywalker/Visuals/blob/master/Circular_bar_charts.py
let me know how far you came!:)
This is not the full answer but you could find some ideas hear :
https://github.com/TronSkywalker/Visuals/blob/master/Circular_bar_charts.py
let me know how far you came!:)
answered Mar 8 at 13:40
Richard LenkiewiczRichard Lenkiewicz
594
594
Technically you would need to replace the zip(..)-loop with a double for-loop over r and the angles. The colors can be intuitively coupled more or less to your z direction.
– Richard Lenkiewicz
Mar 8 at 13:45
add a comment |
Technically you would need to replace the zip(..)-loop with a double for-loop over r and the angles. The colors can be intuitively coupled more or less to your z direction.
– Richard Lenkiewicz
Mar 8 at 13:45
Technically you would need to replace the zip(..)-loop with a double for-loop over r and the angles. The colors can be intuitively coupled more or less to your z direction.
– Richard Lenkiewicz
Mar 8 at 13:45
Technically you would need to replace the zip(..)-loop with a double for-loop over r and the angles. The colors can be intuitively coupled more or less to your z direction.
– Richard Lenkiewicz
Mar 8 at 13:45
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%2f55064339%2fpolar-histogram-in-python-for-given-r-theta-and-z-values%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
Just wanted to say that is a very cool chart
– rgk
Mar 8 at 13:38
Seconding on the cool chart. The closest I've ever encountered is matplotlib.org/basemap/users/paeqd.html but I'm not sure it can be stretched for this kind of output
– roganjosh
Mar 8 at 13:39
Are you sure you want a histogram? That seems to contradict the third requirement "a measured quantity at this specific time". Can you clarify what exactly you need?
– ImportanceOfBeingErnest
Mar 8 at 13:53
Essential what I want to show is a certain characteristic of the measured quantity at a specific radius-azimuth bin. So with histogram what I mean is an occurrence number in the specific radius-azimuth bin. Does that help?
– R Thompson
Mar 8 at 14:20
No, it doesn't. It's easy: Do you have 2 columns,
radius
andazimut
? Then you can plot occurance as histogram. Do you have 3 columns,radius
andazimut
,measured quantity
, then you cannot plot a histogram, but rather themeasured quantity
as a function of the other two. Which one is it?– ImportanceOfBeingErnest
Mar 8 at 17:16