-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Barplots #179
Comments
Hi @EricESeverson that sounds like a reasonable use case and certainly belongs in this library. Ideally all of the pyplot functions would have slider generating equivalents, but I haven't gotten to them all yet. A few questions for you:
Thoughts on implementing Also it looks as though bar can be super flexible https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.bar.html#examples-using-matplotlib-axes-axes-bar so it may be a bit of a bear to fully support updating bars in all those different ways. So I propose starting simple with what I imagine are the basic use cases of a standard bar plot and then adding more as people want them or if someone has the energy to. It will probably also be helpful to borrow good chunks of the code from https://github.com/matplotlib/matplotlib/blob/a051169c1b51a36c270b7b696ec86fae8f2f23e8/lib/matplotlib/axes/_axes.py#L2252 (I really should write a basic guide on how to add a new function - explaining how all the kwarg handling happens etc) |
|
Other things I want for my exact use case is to make this barplot before the simulation data has been generated, then have it get updated live while the simulation is running, with the slider bar left over to go through the data has been generated. And I have a toggle for the y-axis scale to change to 'symlog' to visualize if counts are 0 or close to 0. This seems like easy for your package to do. |
One thing to note is that matplotlib can actually do this as well! You just need to use the
This may actually be really tricky to achieve due to the current limitations of how widgets work. If your simulation is running continuously then the kernel will always be busy, and it won't be able to process the changes to the slider. You can see the issue with this simplified example. If you move the slider around before the sleep is done then the messages won't immediately print out. import ipywidgets as widgets
import time
out = widgets.Output()
@out.capture()
def cb(change):
print(change['new'])
slider = widgets.IntSlider()
slider.observe(cb, names='value')
display(slider)
display(out)
for i in range(5):
# faking doing lots of work for the simulation
time.sleep(2) Although if you are running from a script and using matplotlib sliders it may actually work better - I'm not totally sure. Though the only way I can be sure you'd be able to have this happen live is to do something with threads, but that can get out of hand pretty easily.
I sure hope so! if it ends up not being please either open an issue or ask for help on https://discourse.matplotlib.org/c/3rdparty/18 |
It looks as though that uses
Yeah seaborn can make some awesome stuff. Unfortunately they don't return the underlying matplotlb objects so you can't really animate them see for example (https://github.com/mwaskom/seaborn/blob/10aa7a82130f0560f2b39f857349442f553e5e1a/seaborn/categorical.py#L1554-L1595). My naive guess is that if you want something to be both a complex visualization and animated you're going to end up needing to do one of those two parts manually. I don't think any library really hits both. You could with some work probably animate seaborn,but I think you are correct the easiest thing will be to construct your visualization from pure matplotlib and then animate that (potentially using this library).
That sounds like a great start! This is basically what hist does (except I go even more manual and create the patches from scratch). So I'd recommend starting with just this and getting all the integration with the controls object working - and then we can work on changing more than just the heights. Don't let the perfect be the enemy of the good! If you post what you have so far I can help with how to integrate it into a form that will work with this library.
Right on. FWIW making this package has been a huge python learning experience for me, so I totally get it. As for help through the process my first piece of advice is to not be afraid to post partially working code here, or to open an unfinished PR. It's way easier to discuss these things when we're both looking at the same thing. I also have two resources for learning how to contribute to this library:
( I just wrote #180 inspired by this thread. My hope is that it can make some of the internals clear to someone who would like to contribute. If you end up reading that and find that anything unclear or could be improved please let me know!) |
Sorry about the delay, I have been caught up with getting my project up and running on PyPI.
My StatePlotter class is tied into the Simulator class, and most of the code is involved with manipulating data structures in these classes. The actual bar plot logic is just a couple lines. The labels of the bars come from a field self.ax = sns.barplot(x=[str(c) for c in self.categories], y=np.zeros(len(self.categories))) and then the for i, rect in enumerate(self.ax.patches):
rect.set_height(heights[i]) This seems to be a pretty standard way to do it, in places such as this stack overflow post. My The main thing this still doesn't have that I would like at some point is a good way to get nested barplots. seaborn's barplot function can make these really well with the |
My intended use case is for visualizing data that gives counts of various states over a number of time snapshots. I want to show a barplot where the bar heights are a certain recorded snapshot, and to have a slider that lets me range over all recorded snapshots to see how these counts change over time.
Maybe I missed a way to do this with the library, but I didn't see any specific compatibility with matplotlib barplots. It would be nice to get some of the extra features, like easily saving an animation, that I wouldn't get from just that matplotlib.widgets Slider object.
The text was updated successfully, but these errors were encountered: