I'm trying to build a dynamically customizable plot in jupyter with matplotlib. I already have sliders where I can select how many subplots shall be shown (x*y). But now I want to fill these subplots with data. I have a fix set of data series, and would like to have a context menu when I do a right click on the subplot where I could select the data series that shall be displayed. But I can't find any solution how to pop up a windows on a subplot and return the selected series. Do you have any idea/example for me how to solve this?
Thanks and best regards!
Related
I'm using matplotlib to show a plot with %matplotlib widget in jupyter lab. Almost every time I show the plot, next thing I have to do is zoom in and examine one of the sections of the plot. I would like to be able to show the plot zoomed into that section, and if I want to examine the rest of the plot, as I sometimes do, I would press back button and see all of it.
This is similar to showing subplot with relevant data or using plt.xlim, except I would like to do it in a single plot so the data I'm looking at can occupy more screen space, and plt.xlim just shows relevant stretch of data without possibility to zoom out again.
How do I do this is jupyter lab?
I'm creating an HTML report with a lot of plots and corresponding tables. It's quite big, so it would be great if the user could copy/paste the plot title into Find In Page to quickly find the associated table(s).
This answer made me realise that's not possible and that printing the title to the screen would help.
However, I want to display the charts in 2 columns.
Is it possible to print the title, display a plot, print a title to the right, display a plot to the right, begin next column, and so on, without using plt.subplots()?
If not in matplotlib, are there any plotting packages that could do this?
I have used xlsxwriter to add various different data series (lines) to a plot. What I would like to do now is disable certain series by default but, still have the disabled series available to reenable when looking at the graph.
For example, in the following image, while xlsxwriter adds all the series as I want it to, I would also like to not show "Sample2" & "Sample3" while showing "Sample1" by default.
The only feature I have been able to find that does something similar would be the:
# Delete/hide series index 0 and 2 from the legend.
chart.set_legend({'delete_series': [0, 2]})
It appears to "delete" it more than hide it because if I try to toggle them back on they don't show up.
Maybe it's not possible through xlsxwriter but is there any other way I can implement this functionality?
I hope you're enjoying your stay here lmao.
Delete/hide series index 0 and 2 from the legend.
chart.set_legend({'delete_series': [0, 2]})
This work?
If not...
for Mac:
Click on the chart.
On the ribbon, click Chart Design and then click Select Data.
On the Chart Design tab, click Select Data
This selects the data range of the chart and displays the Select Data Source dialog box.
To edit a legend series, in the Legend entries (series) box, click the series you want to change. Then, edit the Name and Y values boxes to make any changes.
To rearrange a legend series, in the Legend entries (series) box, click the series you want to change and then select the alternate text or alternate text arrows.
Windows:
Right-click your chart, and then choose Select Data.
n the Legend Entries (Series) box, click the series you want to change.
Click Edit, make your changes, and click OK.
Changes you make may break links to the source data on the worksheet.
To rearrange a series, select it, and then click Move Up alternate text or Move Down alternate text.
You can also add a data series or remove them in this dialog box by clicking Add or Remove. Removing a data series deletes it from the chart—you can’t use chart filters to show it again.
If you want to rename a data series, see Rename a data series.
I hope this is helpful to you.
I'm trying to retrieve the range of the x-axis when you zoom in a plotly scatter plot, but when I tried to access it using:
figure['layout']['xaxis']['range']
it just returns 'None'.
This is the code that I am using to create the graph:
# self.plot contains the dataframe passed to the function to be plotted
self.plot = df
# Creates the plotly plot figure
self.fig = self.plot.iplot(asFigure=True,kind='scatter', xTitle='Date', yTitle='Temperature')
# Displays the plot
iplot(self.fig, show_link=False)
I'm using cufflinks to create the plot from a pandas DataFrame so I don't explicitly set the layout.xaxis.range to anything. Also I'm using a Jupyter Notebook to display the graph, if that helps at all. So is there any way of getting the range of the x-axis of the current view window of the plot? Thanks in advance!
That does not seem to be possible at the moment using python. There's a post on community.plot.ly that says:
Graph parameters don’t dynamically change with chart actions. However,
as you zoom, the plot does emit data regarding the new x-axis range,
you’re unable to to access this information directly in Python.
Instead you’d have to use javascript:
https://plot.ly/javascript/zoom-events/
I have been looking for a way to be able to select which series are visible on a plot, after a plot is created.
I need this as i often have plots with many series. they are too many to plot at the same time, and i need to quickly and interactively select which series are visible. Ideally there will be a window with a list of series in the plot and checkboxes, where the series with the checked checkbox is visible.
Does anyone know if this has been already implemented somewhere?, if not then can someone guide me of how can i do it myself?
Thanks!
Omar
It all depends on how much effort you are willing to do and what the exact requirements are, but you can bet it has already been implemented somewhere :-)
If the aim is mainly to not clutter the image, it may be sufficient to use the built-in capabilities; you can find relevant code in the matplotlib examples library:
http://matplotlib.org/examples/event_handling/legend_picking.html
http://matplotlib.org/examples/widgets/check_buttons.html
If you really want to have a UI, so you can guard the performance by limiting the amount of plots / data, you would typically use a GUI toolbox such as GTK, QT or WX. Look here for some articles and example code:
http://eli.thegreenplace.net/2009/05/23/more-pyqt-plotting-demos/
A list with checkboxes will be fine if you have a few plots or less, but for more plots a popup menu would probably be better. I am not sure whether either of these is possible with matplotlib though.
The way I implemented this once was to use a slider to select the plot from a list - basically you use the slider to set the index of the series that should be shown. I had a few hundred series per dataset, so it was a good way to quickly glance through them.
My code for setting this up was roughly like this:
fig = pyplot.figure()
slax = self.fig.add_axes((0.1,0.05,0.35,0.05))
sl = matplotlib.widgets.Slider(slax, "Trace #", 0, len(plotlist), valinit=0.0)
def update_trace():
ax.clear()
tracenum = int(np.floor(sl.val))
ax.plot(plotlist[tracenum])
fig.canvas.draw()
sl.on_changed(update_trace)
ax = self.fig.add_axes((0.6, 0.2, 0.35, 0.7))
fig.add_subplot(axes=self.traceax)
update_trace()
Here's an example:
Now that plot.ly has opened sourced their libraries, it is a really good choice for interactive plots in python. See for example: https://plot.ly/python/legend/#legend-names. You can click on the legend traces and select/deselect traces.
If you want to embed in an Ipython/Jupyter Notebook, that is also straightforward: https://plot.ly/ipython-notebooks/gallery/