I am using matplotlib.pyplot and astropy to build a plot in galactic coordinates and my goal is to show the density of stars in the sky.
For that, the only data I have is a two-column table with the coordinates of the stars in Right Ascension (RA) and Declination (Dec).
Right now my code is doing the following:
import astropy.coordinates as coord
import matplotlib.pyplot as plt
import astropy.units as u
coordinates = coord.SkyCoord(ra=RA*u.deg, dec=DEC*u.deg)
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(111, projection="aitoff")
ax.plot(coordinates.galactic.l.wrap_at('180d').radian,
coordinates.galactic.b.radian, 'k.', alpha=0.01, ms=1)
ax.grid(True)
So for now I am basically using plt.plot to plot all datapoints (which in the case is half-million datapoints) using a very low alpha and symbol size and the plot looks like this:
However, this isn't the plot I want, as the colour scale quickly saturates.
My question is: Is there a way of making a similar plot but properly reflecting the density of datapoint in the z-axis (color)? For example, I want to be able of controling the color table for a given number-density of sources.
I've seen some answers to similar questions are available.
For example, this question (Plotting a heatmap in galactic coordinates) does a similar thing, but for a specific z-axis described by some data.
I am also aware of this question (How can I make a scatter plot colored by density in matplotlib?) and I tried each solution in this post, but they all failed since I am using a subplot which already has a projection.
Any ideas?
I had some data on which I had to do some image processing to obtain the centers of the 4 'circles' (refer figure). I was able to do that correctly using the Blob detection function of the OpenCV library in Python.
I want to plot the lines perpendicular to the x and y axis to indicate these centers on the seaborn heatmap output. I'm unable to do so. I have the co-ordinates for the lines in a separate list.
But I'm unable to plot even one line to begin with.
plt.figure(figsize = (12,8))
sns.heatmap(df_scaled)
plt.axvline(x = -10.86,color='white',linewidth=2) # For now let's assume value of x as -10.86
plt.tight_layout()
plt.show()]
There are previous questions about quiver plots on polar axes in matplotlib, however they concern vector fields. I'm interested in drawing arbitrary vectors on polar axes. If there is a genuine duplicate, please link it.
I'm writing some software which concerns a circular world. I'm plotting an agent's trajectory from the centre of a circular arena to the edge. This is visualised by drawing a vector from the centre of the circle to the edge. I'm trying to use matplotlib's quiver plot to plot vectors on a set of polar axes. Here's a minimum working example:
import matplotlib.pyplot as plt
import numpy as np
if __name__ == '__main__':
fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')
# Plot origin (agent's start point)
ax.plot(0, 0, color='black', marker='o', markersize=5)
# Plot agent's path
ax.quiver((0, 0), (0, 1), color='black')
# Example of where (0, 1) should be
ax.plot(0, 1, color='black', marker='o', markersize=5)
# Plot configuration
ax.set_rticks([])
ax.set_rmin(0)
ax.set_rmax(1)
ax.set_thetalim(-np.pi, np.pi)
ax.set_xticks(np.linspace(np.pi, -np.pi, 4, endpoint=False))
ax.grid(False)
ax.set_theta_direction(-1)
ax.set_theta_zero_location("N")
plt.show()
If you run the code, you get this plot
The plot shows the origin plotted correctly, an example point at (0, 1) to show where the vector should end, then the vector itself which appears far too short (though the direction is correct). From the docs, I understand that quiver takes cartesian coordinates (x,y) denoting the start point of the vector and (u,v) denoting the vector's direction. In my previous experience with quiver (u,v) essentially denotes where the vector's tip will be, so in this case we'd expect the vector to be drawn from (0,0) to (0,1) which isn't the case and I don't know why.
In short, I want to be able to draw arbitrary vectors on a set of polar axes and quiver isn't working as I expected. Three questions:
Is my code actually sensible given my goal? I want to draw a unit vector from the origin to the edge of the polar plot.
Am I completely misunderstanding how to use quiver?
How can I draw arbitrary vectors on polar axes in matplotlib? I know about arrow and I'm going to give that a try though initial attempts were unsuccessful.
Short of using a standard plot and just defining my own polar system within it I'm completely stumped.
You did not specify u and v in ax.quiver(x,y,u,v). To make sure the arrow is 1 unit long you will need to set the scale und units as well.
ax.quiver(0,0,0,1, color='black', angles="xy", scale_units='xy', scale=1.)
I'm looking to plot multiple GPS tracks from lat, long points. I build each plot individually and then show them all on the same final figure. I am wondering if I can use the overlap of the individual plots to define their color at that point. Essentially, I want to create a heatmap based in different colors instead of just alpha, so I can still see every track.
Currently, each plot is simply put together with:
plt.plot(lon, lat, color = 'deepskyblue', lw = 0.2, alpha = 0.8)
I have two figures:
1) networkx graph
2) a normal x-y plot.
1) The variable 'graph' is the Graph created using networkx. 'var' is x-y coordinates of the nodes of graph.
2) Also, I have two plot few points using scatter plot that will super impose on some of the existing points. I tried the following code. coors are the coordinates of x-y plot
fig, ax = plt.subplots()
ax.plot(nx.draw(graph,[(x,y) for x,y in var],node_size=50))
ax.scatter(coors[:,0],coors[:,1])
plt.show()
When I plot each of them separately it works but when I try to plot it together only the networkx comes up. I know they are different because scatter plot is in blue color and networkx graph is in a kinda orange color. Can someone help me out ?