vojtamolda / Plotly.swift

Interactive data visualization library for Swift
https://vojtamolda.github.io/Plotly.swift/
MIT License
82 stars 8 forks source link

Figure Factory #16

Open ProfFan opened 3 years ago

ProfFan commented 3 years ago

Thank you for this awesome library :) Although the schema-based system works really well, I think one of the main hassle in using Plotly.swift is its lack of matplotlib-style plot shorthands like .scatter(x, y), .quiver(x, y, u, v), et cetera. The main Plotly Python API provides figure_factory to automate some of these tasks, for example:

https://plotly.com/python-api-reference/generated/plotly.figure_factory.create_quiver.html

I think it would be awesome if we can have similar functionality so people can start right away using Plotly.swift without having to remember what the schema is for all the different types of figures. I think this could be put in a separate package like PlotlyTools, just like matplotlib.pyplot.

vojtamolda commented 3 years ago

Hello Fan,

I'm glad you like and use the library and I certainly appreciate the kind words. Now, regarding your proposal, I think I see two somewhat separate issues:

vojtamolda commented 3 years ago

BTW, the .show() function in the first bullet point can be implemented with a simple extension of the Trace protocol.

extension Trace {
    @discardableResult
    func show(layout: Layout? = nil, config: Config? = nil) -> Figure {
        let figure = Figure(data: [self], layout: layout, config: config)
        figure.show()
        return figure
    }
}
ProfFan commented 3 years ago

I think this show() method is a great solution! But still, a "easy plotting" module would be really nice. The main problem with the current interface is that you can create plots that is perfectly valid in schema but not actually doing what you want. For example, the axis parameter is really tricky to use as it just doesn't work and there is no error message when you don't understand the inner workings of Plotly.swift and the plotly js library.

vojtamolda commented 3 years ago

Thanks for your comments, Fan. I really appreciate that you took the time to write your feedback.

You're also right about the axis parameters. Just to keep things organized for myself I opened a new thread in #17. I work on this repo in my free time with frequent gaps and it helps me to figure out what I was doing when I come back after a while.