template to handle strings on x axis w/ legend
bool named_plot(const std::string& name, const std::vectorstd::string& x, const std::vector<Numeric>& y, const std::string& format = "") { .. }
added template to be able to have named legend plotting: ex: time(x) vs signal(y) with legend. Prior to this change, the current library implements simple plots with no legends and with this change the above should be possible.
Thanks for contributing!
I'm a bit confused if/why this works, it's not mentioned on the matplotlib docs that x can be a vector of strings: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html
Would you mind adding an example that uses this function, so I can check out that this works as it should?
Hi,
This is needed as Python can handle string conversions easily for some users.. But to look forward to similar functionality in CPP, we sometimes need texts / name plots or here in my case I wanted to have time in "<Month>< >Year" format on the X-Axis.
I used it to represent peak speed reached per month for a vehicle using:
plot::named_plot("Vehicle speed (max)", mon_yy, veh_spd); //
where mon_yy and veh_spd are vectors of which mon_yy is a mix of string and numbers.
The resultant looks similar to this:
[image: image.png] The current implementation will not accept spaces or characters as vectors. Hence just prototyped a simple template for strings.
I hope this helps!
Thank you!
On Fri, Apr 2, 2021 at 4:40 PM Benno Evers @.***> wrote:
Thanks for contributing!
I'm a bit confused if/why this works, it's not mentioned on the matplotlib docs that x can be a vector of strings: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html
Would you mind adding an example that uses this function, so I can check out that this works as it should?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/lava/matplotlib-cpp/pull/254#issuecomment-812702725, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKKMLTO5PKJBV7RQV6QFXY3TGYTS7ANCNFSM4YPAYPNQ .
@lava this is open for more than 2 years. if my response answers your question, can you please merge my pull request ?