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
How to Cleanly Uninstall Ansible
How to Write to an Existing Excel File Without Overwriting Data (Using Pandas)
How to Install Tesseract for Python on Anaconda
Cannot Convert the Series to <Class 'Int''>
No Unique Mode; Found 2 Equally Common Values
Splitting Strings into Numbers (Python)
Django Rest Framework Csrf Failed: Csrf Cookie Not Set
Pyspark Data Frame Converting False and True to 0 and 1
Matplotlib: Attributeerror: 'Axessubplot' Object Has No Attribute 'Add_Axes'
How to Change the Title Bar in Tkinter
Python, Anaconda, Spyder - Uninstalling Python Package Using Pip Does Not Work in Spyder + Ipython
Plotting Data from Multiple Pandas Data Frames in One Plot
Pandas To_Csv: Suppress Scientific Notation in CSV File When Writing Pandas to Csv
Python-Compare Two String Columns in Same Dataframe, Return Matching Result
How to Change a Two Dimensional Array to One Dimensional
How to Convert a List of Dictionaries to Json in Python/Django
Import Error: Dll Load Failed in Jupyter Notebook But Working in .Py File