|
32 | 32 | ax = plt.subplot(1, 1, 1, projection='polar')
|
33 | 33 | # draw the analemma loops
|
34 | 34 | points = ax.scatter(np.radians(solpos.azimuth), solpos.apparent_zenith,
|
35 |
| - s=2, label=None, c=solpos.index.dayofyear) |
36 |
| -ax.figure.colorbar(points) |
| 35 | + s=2, label=None, c=solpos.index.dayofyear, |
| 36 | + cmap='twilight_shifted_r') |
| 37 | +# add and format colorbar |
| 38 | +cbar = ax.figure.colorbar(points) |
| 39 | +times_ticks = pd.date_range('2019-01-01', '2020-01-01', freq='MS', tz=tz) |
| 40 | +cbar.set_ticks(ticks=times_ticks.dayofyear, labels=[], minor=False) |
| 41 | +cbar.set_ticks(ticks=times_ticks.dayofyear+15, |
| 42 | + labels=times_ticks.strftime('%b'), |
| 43 | + minor=True) |
| 44 | +cbar.ax.tick_params(which='minor', width=0) |
37 | 45 |
|
38 | 46 | # draw hour labels
|
39 | 47 | for hour in np.unique(solpos.index.hour):
|
40 | 48 | # choose label position by the smallest radius for each hour
|
41 | 49 | subset = solpos.loc[solpos.index.hour == hour, :]
|
42 | 50 | r = subset.apparent_zenith
|
43 | 51 | pos = solpos.loc[r.idxmin(), :]
|
44 |
| - ax.text(np.radians(pos['azimuth']), pos['apparent_zenith'], str(hour)) |
| 52 | + ax.text(np.radians(pos['azimuth']), pos['apparent_zenith'], |
| 53 | + str(hour).zfill(2), ha='center', va='bottom') |
45 | 54 |
|
46 | 55 | # draw individual days
|
47 | 56 | for date in pd.to_datetime(['2019-03-21', '2019-06-21', '2019-12-21']):
|
48 | 57 | times = pd.date_range(date, date+pd.Timedelta('24h'), freq='5min', tz=tz)
|
49 | 58 | solpos = solarposition.get_solarposition(times, lat, lon)
|
50 | 59 | solpos = solpos.loc[solpos['apparent_elevation'] > 0, :]
|
51 |
| - label = date.strftime('%Y-%m-%d') |
| 60 | + label = date.strftime('%b %d') |
52 | 61 | ax.plot(np.radians(solpos.azimuth), solpos.apparent_zenith, label=label)
|
53 | 62 |
|
54 | 63 | ax.figure.legend(loc='upper left')
|
|
64 | 73 | # This is a polar plot of hourly solar zenith and azimuth. The figure-8
|
65 | 74 | # patterns are called `analemmas <https://en.wikipedia.org/wiki/Analemma>`_ and
|
66 | 75 | # show how the sun's path slowly shifts over the course of the year . The
|
67 |
| -# colored lines show the single-day sun paths for the winter and summer |
| 76 | +# solid colored lines show the single-day sun paths for the winter and summer |
68 | 77 | # solstices as well as the spring equinox.
|
69 | 78 | #
|
70 | 79 | # The soltice paths mark the boundary of the sky area that the sun traverses
|
|
111 | 120 |
|
112 | 121 | fig, ax = plt.subplots()
|
113 | 122 | points = ax.scatter(solpos.azimuth, solpos.apparent_elevation, s=2,
|
114 |
| - c=solpos.index.dayofyear, label=None) |
115 |
| -fig.colorbar(points) |
| 123 | + c=solpos.index.dayofyear, label=None, |
| 124 | + cmap='twilight_shifted_r') |
| 125 | +# add and format colorbar |
| 126 | +cbar = fig.colorbar(points) |
| 127 | +times_ticks = pd.date_range('2019-01-01', '2020-01-01', freq='MS', tz=tz) |
| 128 | +cbar.set_ticks(ticks=times_ticks.dayofyear, labels=[], minor=False) |
| 129 | +cbar.set_ticks(ticks=times_ticks.dayofyear+15, |
| 130 | + labels=times_ticks.strftime('%b'), |
| 131 | + minor=True) |
| 132 | +cbar.ax.tick_params(which='minor', width=0) |
116 | 133 |
|
117 | 134 | for hour in np.unique(solpos.index.hour):
|
118 | 135 | # choose label position by the largest elevation for each hour
|
119 | 136 | subset = solpos.loc[solpos.index.hour == hour, :]
|
120 | 137 | height = subset.apparent_elevation
|
121 | 138 | pos = solpos.loc[height.idxmax(), :]
|
122 |
| - ax.text(pos['azimuth'], pos['apparent_elevation'], str(hour)) |
| 139 | + azimuth_offset = -10 if pos['azimuth'] < 180 else 10 |
| 140 | + ax.text(pos['azimuth']+azimuth_offset, pos['apparent_elevation'], |
| 141 | + str(hour).zfill(2), ha='center', va='bottom') |
123 | 142 |
|
124 | 143 | for date in pd.to_datetime(['2019-03-21', '2019-06-21', '2019-12-21']):
|
125 | 144 | times = pd.date_range(date, date+pd.Timedelta('24h'), freq='5min', tz=tz)
|
126 | 145 | solpos = solarposition.get_solarposition(times, lat, lon)
|
127 | 146 | solpos = solpos.loc[solpos['apparent_elevation'] > 0, :]
|
128 |
| - label = date.strftime('%Y-%m-%d') |
| 147 | + label = date.strftime('%d %b') |
129 | 148 | ax.plot(solpos.azimuth, solpos.apparent_elevation, label=label)
|
130 | 149 |
|
131 |
| -ax.figure.legend(loc='upper left') |
| 150 | +ax.figure.legend(loc='upper center', bbox_to_anchor=[0.45, 1], ncols=3) |
132 | 151 | ax.set_xlabel('Solar Azimuth (degrees)')
|
133 | 152 | ax.set_ylabel('Solar Elevation (degrees)')
|
| 153 | +ax.set_xticks([0, 90, 180, 270, 360]) |
| 154 | +ax.set_ylim(0, None) |
134 | 155 |
|
135 | 156 | plt.show()
|
0 commit comments