Plot doesn't show up in Python on OpenSUSE

Viewed 448

I would like to plot a given graph in Python, however, the graph doesn't show up at all. I use the following code:

import pylab as p

C = [1,2,3,4]
S = [10, 20, 30, 10]
p.plot(C,S)
p.show()

I suspect that it's because I use OpenSUSE with Wayland. Does anyone know a workaround, or how to plot in OpenSUSE Tumbleweed with Python?

All help will be greatly appreciated.

2 Answers

there was another post on this here, with a great answer from ImportanceofBeingErnest, suggesting to to use import matplotlib; matplotlib.use("TkAgg") before import matplotlib.pyplot as plt. You find more on backends on the matplotlib site. You still may have to install the appropriate python-to-toolkit packages, eg. python-tkinter and python3-tk, or try an already installed backend. For example, qt5agg, provides an option to configure some graph parameters interactively.

In Tumbleweed using Python 3.6

open Yast Software Management select python3-matplotlib and I chose python3-matplotlib-tk as backend then install

This installs :- python3-Cycler python3-kiwisolver python3-matplotlib python3-matplotlib-tk python3-numpy python3-olefile python3-Pillow python3-python-dateutil python3-pytz

In python script use :- import matplotlib matplotlib.use('TkAgg') import matplotlib.pyplot as plt import numpy as np

Works for me.

Related