У меня есть код, который рисует несколько графиков и сохраняет их в base64. Однако я получаю следующие предупреждения, хотя я не передал ни один из упомянутых аргументов в savefig (версия matplotlib — 3.4.3):
MatplotlibDeprecationWarning: savefig() got unexpected keyword argument "facecolor" which is no longer supported as of 3.3 and will become an error two minor releases later
fig.savefig(iobytes, format="png")
MatplotlibDeprecationWarning: savefig() got unexpected keyword argument "edgecolor" which is no longer supported as of 3.3 and will become an error two minor releases later
fig.savefig(iobytes, format="png")
MatplotlibDeprecationWarning: savefig() got unexpected keyword argument "orientation" which is no longer supported as of 3.3 and will become an error two minor releases later
fig.savefig(iobytes, format="png")
MatplotlibDeprecationWarning: savefig() got unexpected keyword argument "bbox_inches_restore" which is no longer supported as of 3.3 and will become an error two minor releases later
fig.savefig(iobytes, format="png")
Как от них избавиться?
import base64
import io
from datetime import datetime, timezone
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
class GraphCreator:
LINE_WIDTH = 1
@classmethod
def get_graph(cls, graph_name: str, data: dict) -> str:
graph_map = {
"graph": cls.get_latency_graph,
}
fig = graph_map[graph_name](data)
iobytes = io.BytesIO()
fig.savefig(iobytes, format="png")
iobytes.seek(0)
graph_base64 = base64.b64encode(iobytes.read()).decode()
plt.close(fig)
return graph_base64
@classmethod
def get_latency_graph(cls, data: dict) -> plt.Figure:
latency = []
avg_latency = []
dates = []
for point in data["latency_history"]:
dates.append(cls._get_date(point[0]))
latency.append(float(point[1]))
avg_latency.append(data["raw_average_latency"])
if not all((latency, dates)):
raise ValueError("Missing data")
fig, ax = plt.subplots(
figsize=(data["latency_width"] / 100, data["latency_height"] / 100)
)
ax.plot(dates, latency, label="Latency", color="blue", linewidth=cls.LINE_WIDTH)
ax.plot(
dates,
avg_latency,
label="Average Latency",
color="cyan",
linewidth=cls.LINE_WIDTH,
linestyle="--",
)
ax.set_title(f"Latency: {data['start_end_date']}")
ax.set_ylabel("Latency (ms)")
cls.set_common_line_axes(ax)
fig.tight_layout()
return fig
@staticmethod
def _get_date(timestamp: int) -> datetime:
return datetime.fromtimestamp(timestamp / 1000, tz=timezone.utc)
@staticmethod
def set_common_line_axes(ax: plt.Axes) -> None:
ax.xaxis.set_major_locator(mdates.DayLocator(interval=2))
ax.xaxis.set_major_formatter(mdates.DateFormatter("%b %d"))
ax.xaxis.set_minor_locator(mdates.DayLocator(interval=1))
ax.xaxis.set_minor_formatter(mdates.DateFormatter(""))
ax.yaxis.set_major_locator(ticker.MaxNLocator(integer=True))
ax.tick_params(axis="x", rotation=45)
ax.grid(True, which="major")
ax.legend(loc="upper center", bbox_to_anchor=(0.5, -0.2), ncol=4)
Подробнее здесь: https://stackoverflow.com/questions/790 ... are-not-pa
MatplotlibDeprecationWarning при сохранении фигуры, даже если аргументы не переданы ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
MatplotlibDeprecationWarning при сохранении фигуры, даже если аргументы не переданы
Anonymous » » в форуме Python - 0 Ответы
- 18 Просмотры
-
Последнее сообщение Anonymous
-
-
-
MatplotlibDeprecationWarning при сохранении фигуры, даже если аргументы не переданы
Anonymous » » в форуме Python - 0 Ответы
- 9 Просмотры
-
Последнее сообщение Anonymous
-
-
-
MatplotlibDeprecationWarning при сохранении фигуры, даже если аргументы не переданы
Anonymous » » в форуме Python - 0 Ответы
- 14 Просмотры
-
Последнее сообщение Anonymous
-