Figure

public struct Figure
extension Figure: CustomPlaygroundDisplayConvertible
extension Figure: Encodable

Representation of a Plotly chart.

Plotly‘s graphs are built from two main types of building blocks - traces and layout. Trace describes a single series of data visible in a graph. Traces can be constructed from a wide variety of predefined types, e.g. scatter, heatmap, bar or polar. Layout applies to the entire chart and affect properties like the title, axis annotations and many more.

  • Collection of traces that are displayed on the figure, e.g. Scatter, Bar Polar or Heatmap.

    Declaration

    Swift

    public var data: [Trace]
  • Structure containing layout of the figure.

    Declaration

    Swift

    public var layout: Layout
  • Structure storing Plotly configuration.

    Declaration

    Swift

    public var config: Config
  • Collection of animation frames.

    Declaration

    Swift

    public var frames: [Frame]
  • Output format specification.

    See more

    Declaration

    Swift

    public enum Format
  • Creates a chart displaying the data series from traces with style and configuration from layout and config.

    Traces to Layout Subplot Axis Association

    Constructors collects subplot axis properties , i.e. Trace.xAxis, Trace.yAxis, Trace.polar and so on, of each trace, checks for uniqueness and assigns them to the corresponding Layout container, i. e. Layout.xAxis, Layout.yAxis, Layout.polar and so on.

    The check for uniqueness is a little bit tricky and requires comparison against the .preset static property. The .preset represents the default value implicitly used by Plotly when the subplot axis property isn’t set.

    If a pair of colliding subplot axis is found, the constructor issues an assertion to alert the user about the uid collision. This error means that traces or layout have independent subplot axis with the same uid. This is a serious and hard to find error in Plotly.js because figures with duplicated axis uids don’t look as expected.

    Note

    The duplicate uid assertion is excluded from release builds.

    Declaration

    Swift

    public init(data traces: [Trace], layout: Layout = Layout(),
                frames: [Frame] = [], config: Config = Config())

    Parameters

    traces

    Array of traces that represent the data series displayed on the figure.

    layout

    Settings affecting layout of the figure, i.e. subplots, axis, title, scale, margin, ticks and more.

    frames

    If the figure isn’t animated, an empty array, or animation frames otherwise.

    config

    Configuration of the Plotly library, i.e. toolbar, watermark, scrolling, locale and more.

  • Shows the chart in the default browser.

    Here’s an example that shows figure with a scatter trace:

    let scatterTrace = Scatter(x: [1, 2, 3], y: [4, 6, 5])
    let figure = Figure(data: [scatterTrace])
    try figure.show()
    

    Declaration

    Swift

    @available(iOS 10.0, *)
    public func show(javaScript bundle: HTML.JavaScriptBundleOption = .online) throws
  • Writes chart to a URL using the specified format.

    Warning

    Execution may take a few seconds because the function needs internet access. Current implementation of .included option downloads the library from the CDN server and returns <script> tag with the file content.

    Declaration

    Swift

    @available(iOS 11.0, *)
    public func write<T: StringProtocol>(toFile path: T, as format: Format = .HTML,
                                         javaScript bundle: HTML.JavaScriptBundleOption = .online)
    throws

    Parameters

    path

    File where to save the Figure object.

    format

    Output format (HTML, JSON, …)

    bundle

    JavaScript bundling option (i.e. include, online, exclude) for MathJax and Plotly libraries. Used only for HTML format.

  • Undocumented

    Declaration

    Swift

    func debugQuickLookObject() -> AnyObject
  • Declaration

    Swift

    public var playgroundDescription: Any { get }
  • Declaration

    Swift

    public func encode(to encoder: Encoder) throws