Open ProfFan opened 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:
First, a simple scatter plot requires three steps to display it. You need to create a Trace
object (i.e. Scatter(...)
). Then make the plot itself with the Figure
constructor. And finally display the plot with a call to .show()
. Certainly not an ideal situation and you're right that this deserves an improvement.
What do you think about adding a simple .show()
method to every trace? This would simplify the .scatter(x, y)
factory example to this:
Scatter(x: someX, y: someY).show()
To me this hits the sweet spot of being very concise, readable and flexible. It's short, it is explicit about what it does and allows one to alter the plot by modifying the Scatter
struct later on.
Second, there's certainly a lot of missing plot types. Honestly, I wasn't aware of the figure_factory
module in the plotly
Python package. The features it offers are really nice but I'm not sure if I can devote so much time to this repository and re-implement it in Swift. So PRs would be definitely welcome ;)
I checked the source code and for the most part figure_factory
combine other more "primitive" traces in useful ways or adapts common data formats to a shape friendlier for plotting.
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
}
}
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.
Thanks for your comments, Fan. I really appreciate that you took the time to write your feedback.
[x] The Trace.show()
and display()
methods are already implemented. You can get the 0.4.0
release and check it out for yourself. I also updated the JSON plot schema to the latest version and fixed a few other things.
[ ] Regarding the Figure Factory idea - I agree with you and it certainly has a place here. I didn't express this point well in my previous comment. It certainly would be great to have.
For the time being people can built the functionality themselves from the what's already available here. You're right that it's way less convenient but at least it's possible. Unfortunately, I won't be able to work on this anytime soon so I'll leave the issue open with the help wanted tag. Maybe someone will pick it up and do a PR.
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.
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 ofmatplotlib
-style plot shorthands like.scatter(x, y)
,.quiver(x, y, u, v)
, et cetera. The main Plotly Python API providesfigure_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 likematplotlib.pyplot
.