How to Display a Plot in Fullscreen

Saving Matplotlib graphs to image as full screen

The method you use to maximise the window size depends on which matplotlib backend you are using. Please see the following example for the 3 most common backends:

import matplotlib.pyplot as plt

plt.figure()
plt.plot([1,2], [1,2])

# Option 1
# QT backend
manager = plt.get_current_fig_manager()
manager.window.showMaximized()

# Option 2
# TkAgg backend
manager = plt.get_current_fig_manager()
manager.resize(*manager.window.maxsize())

# Option 3
# WX backend
manager = plt.get_current_fig_manager()
manager.frame.Maximize(True)

plt.show()
plt.savefig('sampleFileName.png')

You can determine which backend you are using with the command matplotlib.get_backend(). When you save the maximized version of the figure it will save a larger image as desired.

Add a button in full screen mode to reset to normal mode in two plots in a shiny app

Don't define JavaScript functions with the same names. Also don't use duplicated ids in HTML.

js <- "
function openFullscreen(elem, plotselector) {
$(plotselector).addClass('fullscreen');
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.mozRequestFullScreen) { /* Firefox */
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
elem.webkitRequestFullscreen();
} else if (elem.msRequestFullscreen) { /* IE/Edge */
elem.msRequestFullscreen();
}
}
function exitFullscreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitExitFullscreen) { /* Safari */
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) { /* IE11 */
document.msExitFullscreen();
}
}"

fluidRow(
column(
width = 3,
actionButton(
"fs", "Full screen",
onclick = "$('#exitbtn').show(); openFullscreen(document.getElementById('frame'), '#ggplot');"
)
),
column(
width = 9,
div(
id = "frame",
plotOutput("ggplot"),
actionButton(
"exitbtn", "Exit",
onclick = "exitFullscreen(); $('#ggplot').removeClass('fullscreen'); $(this).hide();"
)
)
)
),
fluidRow(
column(
width = 3,
actionButton(
"fs2", "Full screen",
onclick = "$('#exitbtn2').show(); openFullscreen(document.getElementById('frame2'), '#ggplot2');"
)
),
column(
width = 9,
div(
id = "frame2",
plotOutput("ggplot2"),
actionButton(
"exitbtn2", "Exit",
onclick = "exitFullscreen(); $('#ggplot2').removeClass('fullscreen'); $(this).hide();"
)
)
)
)

The CSS class fullscreen2 is not needed.



Related Topics



Leave a reply



Submit