Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib does not plot when using Apache Livy interpreter on Zeppelin

I am unable to use matplotlib with Apache Livy 0.5 on Zeppelin 0.8. Paragraph does not display the plot. Please check the sample code below:

%livy.pyspark
import matplotlib.pyplot as plt
plt.plot([1, 2, 3])

I am getting the following output

[<matplotlib.lines.Line2D object at 0x112774990>]

I also tried adding plt.show() but then the paragraph is never reaching finish state.

like image 542
Harvinder Singh Avatar asked Jun 02 '26 12:06

Harvinder Singh


1 Answers

I am not sure if this works the same in Zeppelin, but in Jupyter with Sparkmagic/Livy you need to

1. Register the DataFrame first

df.createOrReplaceTempView('tblName')

2. Run a %%sql cell magic to query the data, and output it to the local space

%%sql -o Name_of_local_DataFrame -n 500

SELECT * FROM tblName

This is taken from the GitHub sparkmagic page (sparkmagic)

3. Plot it locally

%%local

%matplotlib inline

... (your matplotlib code here; access the data via Name_of_local_DataFrame)

If this does not work, maybe share some more information on your setup and how you connect to your cluster.

like image 68
RaspyVotan Avatar answered Jun 04 '26 11:06

RaspyVotan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!