I am trying to rotate the following figure around the vertical green axis drawn:
However, I'm running into trouble trying to set the correct elevation and azimuthal values in order to correctly rotate my figure.
For example,
for i in range(0,360):
axU.view_init(100-i,-90+i)
plt.draw()
plt.savefig('./gif1/rot%i.jpg'%i,dpi=100)
gives me a figure like
http://imgur.com/b26d0V2
and
for i in range(0,360):
axU.view_init(100,-90+i)
plt.draw()
plt.savefig('./gif1/rot%i.jpg'%i,dpi=100)
looks something like:
http://imgur.com/3wdN8zT
both give me too much rotations around unwanted axes, where as I really just want to pan around the green axis drawn above. Is there any way to do this?
for i in range(0,360):
axU.view_init(100-i,-90)
plt.draw()
plt.savefig('./gif1/rot%i.jpg'%i,dpi=100)
This give me something similar to what I want, where the rotation is uniform around one axis, but this rotates around the horizontal green axis whereas I would like it to rotate around the vertical green axis.
rotation
http://imgur.com/b4zeUiI
Related
I'm trying to make a plot of the earth in geocentric solar ecliptic coordinates. This is a coordinate system centered at the earth's center and where +x points towards the sun, +z is parallel to the north ecliptic pole (aka, normal to the plane in which the earth orbits the sun), and +y is towards dusk.
To do this, I'm calculating the subsolar point and using that to find the point on the earth's surface (in latitude/longitude) that lines up with the Z axis. Then I'm making an orthographic projection of the Earth using cartopy, centered at the calculated latitude and longitude.
This is the graph I'm creating
I'm centering the map at the correct location. However, the problem is that I can't figure out how to rotate the map in two dimensions left and right. The only keywords the projection takes are central_longitude, central_latitude, and globe. There's nothing to tell it which way to rotate. It seems like cartopy only allows maps to be made so north is facing up, but I need to rotate the map sideways so the sun is facing the right side instead of the bottom.
Here's the code to generate that plot:
fig = plt.figure(figsize=(18,9))
t = dt.datetime(2014,12,30,0,0,0)
subsolar_lat, subsolar_long = sun_pos(t)
# Center at north ecliptic pole (GSE)
proj_long = subsolar_long
proj_lat = 90-abs(subsolar_lat)
proj=ccrs.Orthographic(proj_long, proj_lat)
left, bottom, width, height = [0.25, 0.25, 0.5, 0.5]
ax = fig.add_axes([left, bottom, width, height], projection = proj)
# Make the map look good
ax.gridlines()
ax.set_global()
ax.set_title(f"{t}")
ax.coastlines()
ax.add_feature(cf.OCEAN, alpha=0.2)
ax.add_feature(cf.LAND, alpha=0.5)
fill_dark_side(ax, time=t, color='black', alpha=0.5)
I found this question on StackOverflow which seems to be exactly what I'm trying to do. However, no one answered it, and their edit doesn't really solve my question either.
I've also tried a few different ways to rotate the axis, but none of them seem to work with Cartopy.
Is there a way to apply a transformation to this projection or to rotate an axis that uses Cartopy?
If you want to rotate the whole axis, matpltolib's floating_axes might help?
https://matplotlib.org/stable/gallery/axisartist/demo_floating_axes.html
https://stackoverflow.com/a/21654433/9703451
I have a 2D color plot that looks like this:
and I want to add a horizontal line running across it, indicating a particular time delay value. Is there a way to do this using matplotlib?
Do you mean an axhspan?
This will draw an horizontal line at the height or the special value from the left border to the right border of your ax. The y-values are in the data coordinates while the x-values are in Axes coordinates.
ax.axhspan(special_value, special_value, xmin=0, xmax=1, color="red")
You can specify a big upper/lower boundary so that the whole area above/below that special value is colored too, or you can use an axhline as suggested by #import random if you want a single line.
I have a 3D projection plot which is really a collection of 2D slices of some value. I also shade the underlying area with:
ax.add_collection3d(plt.fill_between())
I have a couple of related questions:
1) The plot looks fine but the axis labels look messed up - they are rendered on top of the tick labels. How can I space them out a bit?
2) How can I choose what camera angle is rendered? (I'm using Jupiter notebook).
3) The background of the plot (behind the grid, not the grid color itself) is this light blueish grey. how can make that white?
Thanks!
for number 1) ax.set_xlabel() has a labelpad parameters that can be set to any number of pixels.
Using matplotlib I have generated the polar plot below, which shows the angle and distance to aircraft nearby (calculated using the haversine formula). This plot is composed of 56132 individual points.
The code for this is almost the same as the examples from the documentation:
ax = plot.subplot(111, polar=True)
# Orient the plot with north (0 degrees) to the top
ax.set_theta_zero_location('N')
ax.set_ylim(bottom=0, top=100)
c = plot.scatter(r, t)
plot.savefig('test.png')
Where r is a list of radian angles and t is the corresponding distance.
I can also process the data and just draw the outline. To do this I converted all radian angles to 0-359 degrees, found the highest distance measurement and plotted the result with a line:
My specific question is: can I somehow draw a smoother outline around the points? Preferably filled with a gradient outward from the centre.
However if anybody can suggest general ways of making this data more visually appealing that would also be excellent.
If you are looking for a way to fill the area, you might consider a pseudocolor heatmap (pcolor), or a filled contour (contourf), which are available in matplotlib (For example: http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.pcolor). Getting them to work in this case might be tricky - you might need to convert your plot points to a rectangular grid in order for it to work.
Alternatively, you could try finding the several percentile values for each angle, (instead of just the largest) and draw multiple lines in different colors.
This one is a quick and easy one for the matplotlib community. I was looking to plot an L-shaped gridspec layout, which I have done:
Ignoring a few layout issues I have for the moment, what I have is that the x-axis in the gs[0] plot (top left) shares the x-axis with the gs[2] plot (bottom left) and the gs[2] shares its y axis with the gs[3] plot. Now, what I was hoping to do was update the w-space and h-space to be tighter. So that the axes are almost touching, so perhaps wspace=0.02, hspace=0.02 or something similar.
I was also hoping that the bottom right hand plot was to be longer in the horizontal orientation, keeping the two left hand plots square in shape. Or as close to square as possible. If someone could run through all of the parameters I would be very appreciative. I can tinker then in my own time.
To change the spacings of the plot with grid spec:
gs = gridspec.GridSpec(2, 2,width_ratios=[1,1.5],height_ratios=[1,1])
This changes the relative size of plot gs[0] and gs[2] to gs1 and gs[3], whereas something like:
gs = gridspec.GridSpec(2, 2,width_ratios=[1,1],height_ratios=[1,2])
will change the relative sizes of plot gs[0] and gs1 to gs[2] and gs[3].
The following will tighten up the plots:
gs.update(hspace=0.01, wspace=0.01)
This gave me the following plot:
I also used the following to remove the axis labels where needed:
nullfmt = plt.NullFormatter()
ax.yaxis.set_major_formatter(nullfmt)
ax.xaxis.set_major_formatter(nullfmt)