Skip to content

Trouble using plots with TabPy #401

@ethantjones97

Description

@ethantjones97

I would like to be able to use plots created in Python (i.e. plots generated from matplotlib or seaborn) in my Tableau workbooks. See the below code in my attempt to make a simple sine plot and show it in a Tableau workbook.

`import json
import base64
import numpy as np
import math
import matplotlib.pyplot as plt
from tabpy.tabpy_tools.client import Client
connection = Client('http://localhost:9004/')

def SinePlot(freq, amp):
x = np.array(np.linspace(1,100,100))
y = []
for i in range(len(x)):
y_i = math.sin(x[i])
y.append(y_i)
i += 1
fig = plt.figure()
ax = plt.subplot(111)
ax.plot(x, y)
plt.title('Sine Wave')
plt.legend('sin')
fig.savefig('plot.png')
data = {}
with open('plot.png', mode='rb') as file:
img = file.read()
data['img'] = base64.encodebytes(img).decode("utf-8")
answer = json.dumps(data)
return answer

connection.deploy('SinePlot Func',
SinePlot,
'Plots a sine wave', override = True)

print('done')`

sine plot test

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions