Created
September 11, 2024 14:09
-
-
Save michaelaye/6d3ec46ed1745a50d73517f4cd69f064 to your computer and use it in GitHub Desktop.
example from claude for log polar plot...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib.colors import LogNorm # Add this import | |
# Generate some sample data | |
np.random.seed(42) | |
angles = np.random.uniform(0, 2*np.pi, 1000) | |
radii = np.random.normal(5, 1, 1000) | |
# Create a polar subplot | |
fig, ax = plt.subplots(subplot_kw=dict(projection='polar')) | |
# Create histogram bins | |
nbins = 36 | |
angle_bins = np.linspace(0, 2*np.pi, nbins+1) | |
radius_bins = np.linspace(0, 10, 10) | |
# Create the 2D histogram | |
hist, _, _ = np.histogram2d(angles, radii, bins=(angle_bins, radius_bins)) | |
# Plot the histogram using pcolormesh | |
pcm = ax.pcolormesh(angle_bins, radius_bins, hist.T, norm=LogNorm()) # Use LogNorm() directly | |
# Customize the plot | |
ax.set_theta_zero_location('N') | |
ax.set_theta_direction(-1) | |
ax.set_rlabel_position(0) | |
ax.set_ylim(0, 10) | |
# Add a colorbar | |
plt.colorbar(pcm, label='Count (log scale)') | |
plt.title('Polar Plot with Logarithmic Histogram') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment