Create resizable plot layout with different sized sections in Bokeh - python

Can I create a Bokeh layout where the widgets section is set to be e.g. 10% of the screen height with plot section at 90%?
I'm trying to avoid manually re-sizing my plot and using sizing_mode='fixed' which wouldn't work with resizing the browser window.
Currently have:
layout = layout(
[plot],
[[button, slider]],
sizing_mode='stretch_both'
)
In this case, the bottom half of screen is filled entirely by the stretched button/slider.

There is currently (as of 1.3.4) no mechanism to specify a percentage, but you can put the widgets in a row and give that a fixed height while letting the plot vary. Here is one way:
layout = column(
plot,
row(button, slider, height=100, sizing_mode="stretch_width"),
sizing_mode="stretch_both"
)

Related

PyQt scroll Area with custom widget and spacer

I want to make a list of custom widget vertically aligned, where I dynamically add the custom widget inside a scroll Area.
If I click on "add image", a custom widget is added to the scroll area with vertical layout.
like this :
Note that I didn't succeed to make the scroll Area expand as I add widget inside, I had to put a big minimum height to make a scrollbar appear.
The second issue is, when i add like this my widget they are spaced to much, and not added under each other. To prevent this I tried to add a vertical spacer. However, with the vertical spacer, the widget added by clicking on "add image" does not appear anymore (I use insertWidget(Vlayout.count()-1, mycustomwidget)
I organised everything like this :
the pushbutton is an example, I add my custom widget here.
Why the scroll Area doesn't expand as I had widget ? I tried :
self.scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.scroll.setWidgetResizable(True)
Why, when I had a spacer, the widget does not appear anymore ?

How to properly display QChart using QGraphicsScene?

I would like to display a QChart in my GUI using QGraphicsScene and QGraphicsView. I tried to do it as follows:
chart = QChart()
chart.addSeries(series)
scene = QGraphicsScene()
scene.setSceneRect(MyGraphicsView.sceneRect())
scene.addItem(chart)
MyGraphicsView.setScene(scene)
The problem is that the chart is not resized to the size of the scene, but displayed in its corner. I know, that I could use the QChartView, but I already use this QGraphicsScene in many places of my application and would prefer to have it this way.
Thanks for any suggestions.
The scene takes almost the whole grey area in the middle and the chart takes only a fraction of it.

strange matplotlib resizing behavior

I'm embedding matplotlib in my PyQt 4 application and using it to display images. The matplotlib control is being displayed in a QDockWidget, and I'm setting some its parameters as follows:
imagePlot = self.axes.imshow(myNumpyArray, interpolation = "nearest")
imagePlot.axes.set_axis_off()
imagePlot.axes.get_xaxis().set_visible(False)
imagePlot.axes.get_yaxis().set_visible(False)
self.fig.subplots_adjust(bottom = 0, top = 1, left = 0, right = 1)
This has the desired effect i.e. the image is displayed filling as much space as possible in the QDockWidget while maintaining the aspect ratio. I can resize the dock widget by shrinking it horizontally and then expanding it and the image display is correct (filling as much space as possible while maintaining the aspect ratio). Now, if I add the following line:
imagePlot.axes.set(adjustable = "datalim")
I get unexpected behavior. Initially the image is displayed in the same manner as before, but after shrinking and expanding horizontally matplotlib seems to introduce a border around the data. For example, here's the image as it is displayed initially (and correctly):
And here's what matplotlib displays after I drag the side of the containing dock widget and shrink, then expand back to original size. Note the appearance of the border around the image.
What is causing this and how can I prevent it? Thank you.

Relative size of Python Tkinter scale widget

I'm using the place() method of assigning the location of slider bars on my application window. I am using relx, rely, and relwidth to control where the sliders go to make sure they scale up when I maximize the window.
The slider bars are in a horizontal position, and take up most of the width of my screen. I can't figure out how to adjust the "thickness/height?" of the slider bar relative to the screen.
You can do width = ... to adjust the thickness permanently, but I'm finding that you can't use relheight = ... to do it relative to the screen.
Can someone help me adjust this parameter relative to the parent widget size?
sweetSlider = Scale(app, orient=HORIZONTAL,width=30,from_=0,to=100,showvalue=0,variable=sweetVar)
sweetSlider.place(relx=0.15,rely=0.06,relwidth=0.7)
In the above, relx and rely are the placement of the upper left corner of the slider on my GUI screen (app). relwidth=0.7 sets the width of the slider always to 70% the width of the screen.
I wish to set the other dimension of the slider, the "height" in the same manner (to maybe 10% of the screen size). The relheight parameter works with buttons, but it doesn't seem to work with the slider.

How to make matplotlib:pyplot resizeable with the Tkinter window in Python?

I am trying to build a grid of frames in each there is a matplotlib figure.
When I resize the window the figure remain with fix size and are not resizing to fit the empty space.
Is there a way to make the figure change its size according to the canvas (hopefully that it does change with the window size)?
This is how I do the embedding in each frame:
self._figure = pyplot.figure(figsize=(4,4))
self._axes = self._figure.add_subplot(111)
self._canvas = FigureCanvasTkAgg(self._figure, master=self._root)
self._canvas.get_tk_widget().grid(row=1,column=1,rowspan = 4)
This is most likely related to this question. The gist is that there are two parts to making a Tk grid cell grow:
Use the sticky keyword when applying grid to your widget, e.g., widget.grid(..., sticky=Tkinter.NSEW (Python 2.7) to make widget be able to grow in all four directions. See this documentation for more details.
Tell the parent/master to make the respective column/row grow when resizing by calling parent.grid_columnconfigure(...) and/or parent.grid_rowconfigure(...) with the desired row, column, and weight keyword. E.g., parent.grid_columnconfigure(col=0, weight=1) makes the first column take all available space (as long as there are no other columns, or they have not been similary configured). See the grid_columnconfigure documentation and the grid_rowconfigure documentation for more details, e.g., about how the weights affect multiple columns/rows.
This page contains many more details about grid layouts.

Categories

Resources