0

When I open the folder through windows powershell it works, but through ubuntu it doesn't work

import matplotlib.pyplot as plt
import psycopg2
import os
import sys

cur.execute(f"SELECT date as date, revenue_rates_usd ->> '{desired_currency}' AS {desired_currency} FROM usd_rates WHERE date BETWEEN '{start_date}' AND '{end_date}';", conn)
dates = []
values = []

for row in cur.fetchall():
    # print(row[1])
    dates.append(row[0])
    values.append(row[1])
plt.plot_date(dates, values, "-")
plt.title(f'Exchange from USD to {desired_currency}')
plt.show()

That is how I run it:

 /mnt/c/Users/owner/Desktop/Tamatem/.venv/bin/python /mnt/c/Users/owner/Desktop/Tamatem/report.py JOD 2021-07-1 2021-07-22

And when I run it, there is no any errors.

1 Answers1

1

You might have to change the "backend".

import matplotlib
matplotlib.use('Agg')

Do you call the show() method inside a terminal or application that has access to a graphical environment?

Also try to use other GUI backends (TkAgg, wxAgg, Qt5Agg, Qt4Agg).

Further information how this can be done here:How can I set the 'backend' in matplotlib in Python?

nikolim
  • 11
  • 1
  • 5
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/29457170) – dm2 Jul 24 '21 at 12:11
  • 2
    Thanks for the hint - I will change the answer accordingly – nikolim Jul 24 '21 at 12:29