def get_plot_formatting(ax: Axes, series: MediaResource, index_attribute: str, by: str, scheme: str) -> Axes: """ Formats the plot aesthetics Parameters ---------- ax: matplotlib.axes._subplots.AxesSubplot The plot to format Returns ---------- ax : matplotlib.axes._subplots.AxesSubplot """ color_scheme_label = scheme if scheme in colorschemes else 'graphtv' color_scheme = colorschemes.get(color_scheme_label) background_color = color_scheme.background tick_color = color_scheme.ticks font_color = color_scheme.font ax.patch.set_facecolor(background_color) ax.spines['bottom'].set_color(background_color) ax.spines['top'].set_color(background_color) ax.spines['left'].set_color(background_color) ax.spines['right'].set_color(background_color) # change the label colors [i.set_color(tick_color) for i in plt.gca().get_yticklabels()] [i.set_color(tick_color) for i in plt.gca().get_xticklabels()] # Change tick size ax.tick_params(axis='y', which='major', labelsize=22) ax.tick_params(axis='y', which='minor', labelsize=22) ax.yaxis.grid(True) ax.xaxis.grid(False) # Add series parameters episode_indicies = [ float(episode[index_attribute]) for season in series.seasons for episode in season ] # Set plot bounds x_min = min(episode_indicies) x_max = max(episode_indicies) if by == 'index': x_max += 1 else: x_min -= 1 / 12 x_max += 1 / 12 ax.set_xlim((x_min, x_max)) ax.set_ylim(ymax=10) plt.xlabel(index_attribute, fontsize=16, color=font_color) plt.ylabel('imdbRating', fontsize=16, color=font_color) plt.title(series.title, fontsize=24, color=font_color) return ax
def _setup_axes_for_russian_regions_stat(self, ax: _figure.Axes, title: str = None, grid: bool = True, legend: bool = True, draw_key_dates: bool = True): ax.xaxis_date() if draw_key_dates: self.key_russian_dates(ax) if legend: ax.legend(loc='upper left') ax.set_ylim(bottom=0) if grid: ax.grid(axis='y', color='black', linestyle='dashed', alpha=0.4) if title: ax.set_title(title)
def _draw_subplot(subplot: Subplot, ax: Axes, start: datetime.datetime, end: datetime.datetime): data_series = [line.load(start, end) for line in subplot.lines] for line, data in zip(subplot.lines, data_series): _draw_series(data, ax, line) if subplot.ylim: if np.isfinite(subplot.ylim[0]): ax.set_ylim(bottom=subplot.ylim[0]) if np.isfinite(subplot.ylim[1]): ax.set_ylim(top=subplot.ylim[1]) ax.set_ylabel(subplot.ylabel, fontsize=subplot.plot.fontsize(1.2)) # Show log book entries for the logsite of this subplot # Draw only logs if logsite is a site of the subplot's lines if subplot.logsite in [l.siteid for l in subplot.lines]: # Traverse logs and draw them for logtime, logtype, logtext in subplot.get_logs(): x = np.datetime64(logtime) ax.axvline(x, linestyle='-', color='r', alpha=0.5, linewidth=3) ax.text(x, ax.get_ylim()[0], logtype, ha='left', va='bottom', fontsize=subplot.plot.fontsize(0.9)) ax.set_xlim(subplot.plot.start, subplot.plot.end) for xtl in ax.get_xticklabels(): xtl.set_rotation(15) ax.yaxis.set_major_locator(MaxNLocator(prune='upper')) ax.tick_params(axis='both', which='major', labelsize=subplot.plot.fontsize(1.1)) ax.grid() ax.legend(loc=0, prop=dict(size=subplot.plot.fontsize(1)))