9

プロットが HTML にレンダリングされ、Web のような環境に埋め込むことができることを知っています。PyQt アプリケーションの HTML ウィンドウ内でそれを行うことができるのだろうか? 具体的には、インターネットに接続していないオフラインで機能するかどうかを知りたいです。

編集:

これは、matplotlib を使用して最終的にグラフを埋め込んだ方法の抜粋です。

from PyQt4 import QtGui

from matplotlib.backends.backend_qt4agg \
    import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg \
    import NavigationToolbar2QT as NavigationToolbar
import matplotlib.pyplot as plt


class Contour(QtGui.QFrame):

    def __init__(self, parent=None):
        super(Contour, self).__init__(parent)

        self.parent = parent

        # a figure instance to plot on
        self.figure = plt.figure(figsize=(20, 30))
        r, g, b = 100./255., 100./255., 100./255.
        self.figure.patch.set_facecolor(color=(r, g, b))

        # this is the Canvas Widget that displays the `figure`
        # it takes the `figure` instance as a parameter to __init__
        self.canvas = FigureCanvas(self.figure)

        # this is the Navigation widget
        # it takes the Canvas widget and a parent
        self.toolbar = NavigationToolbar(self.canvas, self)

        # set the layout
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.toolbar)
        layout.addWidget(self.canvas)
        self.setLayout(layout)

そして、別の関数で:

    # create an axis
    ax1 = self.figure.add_subplot(211, frame_on=False)
    ax2 = self.figure.add_subplot(212, frame_on=False)

    # plot data
    r, g, b = 39./255., 40./255., 34./255.
    ax1.plot(x, y, ls='o', color=(r, g, b), linewidth=3)
    ax1.plot(coo[0], coo[1], 'go', zorder=20)  # leading edge
    ax1.plot(xg, yg, 'mo', zorder=30)  # leading edge
    ax1.plot(xr, yr, 'yo', zorder=30)  # curvature circle center
    ax1.add_patch(circle)
    ax1.set_title('Contour', fontsize=14)
    ax1.set_xlim(-10.0, 110.0)
    # ax1.set_ylim(-10.0, 14.0)
    r, g, b = 249./255., 38./255., 114./255.
    ax1.fill(x, y, color=(r, g, b))
    ax1.set_aspect('equal')

    ax2.plot(coo[0], gradient, 'go-', linewidth=3)
    ax2.set_title('Gradient', fontsize=14)
    ax2.set_xlim(-10.0, 110.0)
4

4 に答える 4

10

私はかつて次のものを使ってみました:

import plotly.offline as plt
.
.
.
plt.plot(fig, filename=testName + '__plot.html')

次に、プロットを生成しようとしました..これにより、HTMLファイルが得られ、QWebViewをURLプロパティとして配置しようとしました[レンダリングするかどうかを確認するためだけに]。

参照用の画像は次のとおりです。

Render :: Plotly Offline :: QtWebView

于 2016-03-26T00:58:51.223 に答える
2

Plotly は主に、ブラウザーでのグラフ作成を簡単にするために開発されました。PyQT や Tkinter のような UI フレームワークに組み込むことはできないと思います。Plotly には、インターネットに接続せずに社内ネットワークで動作するエンタープライズ バージョンがあります。

PyQT にグラフを埋め込む必要がある場合は、PyQtgraph または MatPlotLib を使用することをお勧めします。

グラフを png としてエクスポートし、png 画像を PyQT アプリケーションに埋め込むサンプル コードを次に示します。

import matplotlib.pyplot as plt
plt.plot([1,2,3,4,5], [10,20,30])
plt.savefig('graphs.png')

import os,sys
from PyQt4 import QtGui
pic.setPixmap(QtGui.QPixmap("graphs.png"))
于 2015-05-09T01:38:11.360 に答える
0

あなたが持っていることを考えると、これがあなたのニーズを完全に満たしているかどうかはわかりません

import plotly.plotly as py

画像を保存してから

py.image.save_as({'data': data}, 'your_image_filename.png')
pic.setPixmap(QtGui.QPixmap("your_image_filename.png"))

警告、私はこれを試していません

于 2015-06-02T17:06:23.983 に答える