Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Add png for jupyter nb and saving #382

Merged
merged 5 commits into from
Nov 9, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions qcodes/plots/pyqtgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,19 @@ def _cmap(self, scale):
values, colors = scale

return self.rpg.ColorMap(values, colors)

def _repr_png_(self):
"""
Create a png representation of the current window.
"""
image = self.win.grab()
byte_array = self.rpg.QtCore.QByteArray()
buffer = self.rpg.QtCore.QBuffer(byte_array)
buffer.open(self.rpg.QtCore.QIODevice.ReadWrite)
image.save(buffer, 'PNG')
buffer.close()
return bytes(byte_array._getValue())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: this is a gnarly hack IMHO, but then again no other way around.


def save(self, filename=""):
image = self.win.grab()
image.save(filename, "PNG", 0)