I think I am doing something wrong here, but would love to know what it is. At least by me, this code displays the image I want, but saves a blank image (can see grid, but no bars). Also, please forgive in advance if this code does not show up as formatted code, it’s my first post here, and couldn’t figure out how to do that
I’ve added the import statements (sorry for leaving these out before).
The code I run to save appears at the bottom of the code below, but am repasting it here for convenience
py.image.save_as(fig, '/data/testh.pdf')
Thanks for the help!
Tali
import plotly.plotly as py
import plotly.graph_objs as go
def score_bar_test(values, groups=[0,1], colors=['#1f77b4', '#ff7f0e']):
traces = []
for i in range(len(values)):
traces.append(go.Bar(
x=values[i],
y=i,
orientation = 'h',
name=groups[i]
))
layout = go.Layout(
barmode='group',
showlegend=False,
width=300,
height=400,
xaxis=dict(
ticks='',
showticklabels=False
),
yaxis=dict(
ticks='',
showticklabels=False
)
)
fig = go.Figure(data=traces, layout=layout)
return fig
values = [1, 1]
fig = score_bar_test(values)
py.image.save_as(fig, '/data/testh.pdf')
py.iplot(fig,filename='tryingbars')
Do you have a Student/Personal/Professional plot.ly plan (https://plot.ly/products/cloud/)? I don’t have one set up right now so I can’t test the PDF export. I get the full image when I save to a *.png format though (e.g. py.image.save_as(fig, '/data/test.png')). Do you?