Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def _build_chart(self, data: List[Dict[str, Any]]) -> str:
- plt.rcParams["figure.figsize"] = [15, 5]
- plt.rcParams["figure.autolayout"] = True
- plt.rcParams['font.size'] = 18
- x_data, y_data, colors = [], [], []
- for record in data:
- index = int(record.get("index"))
- if self.current_date.day < index:
- value, color = record.get("expected"), "#00B690"
- else:
- value, color = record.get("current"), "#22005B"
- plt.bar(index, value, color=color)
- x_data.append(index)
- plt.xticks(x_data)
- plt.gca().axes.get_yaxis().set_visible(False)
- plt.gca().axes.spines['top'].set_visible(False)
- plt.gca().axes.spines['left'].set_visible(False)
- plt.gca().axes.spines['right'].set_visible(False)
- plt.gca().axes.spines['bottom'].set_visible(False)
- plt.margins(x=0)
- plt.tick_params(bottom=False)
- s = io.BytesIO()
- plt.savefig(s, bbox_inches='tight', pad_inches=0, format='png')
- plt.close()
- uploaded_image = upload_file_by_credentials_from_config(
- base64_image=base64.b64encode(s.getvalue()).decode("utf-8").replace("\n", ""),
- upload_to=config.COMPANIES_CHARTS_UPLOAD_TO,
- is_private=False,
- is_image=True,
- )
- return AwsS3Processor.generate_url_to_file(
- file_name=uploaded_image, bucket_name=config.AWS_IMAGES_S3_BUCKET, is_private=False
- )
Add Comment
Please, Sign In to add comment