How to maximize plt.show() using python on mac?
I had the same issue and I simply used a different back-end than MacOSX one.
Try:
plt.switch_backend('Qt4Agg')
figM = plt.get_current_fig_manager()
figM.window.showMaximized()
You can also switch your backend in the default matplotlibrc file, but I prefer the above method for a quick workaround, as I use the MacOSX regularly.
matplotlib 2.2.2 maximize plot
In your previous installation you used PyQt where showMaximized()
is available.
In your new installation you are using Tkinter, which does not have a showMaximized()
.
Two options:
Install PyQt for your new installation and use it e.g. via
import matplotlib
matplotlib.use("Qt5Agg")Keep working with Tkinter, but change your code to tk, i.e.
F1.canvas.manager.frame.Maximize(True)
or any other option listed in
How to maximize a plt.show() window using Python
How to automatically save maximized window when saving animation when using matplotlib
You can obtain the dimensions you want by adjusting figsize
using:
fig, ax = plt.subplots(figsize=(20, 10))
where 20
and 10
are respectively width and height of the figure in inches
and you can also provide a dpi
option (defaults to 100
) :
fig, ax = plt.subplots(figsize=(20, 10), dpi=80)
When you save the figure, dpi
option is still available:
plt.savefig("test.png", dpi=80)
For animations, it's the same:
ani.save("test.mp4", dpi=80)
How to make savefig() save image for 'maximized' window instead of default size
You set the size on initialization:
fig2 = matplotlib.pyplot.figure(figsize=(8.0, 5.0)) # in inches!
Edit:
If the problem is with x-axis ticks - You can set them "manually":
fig2.add_subplot(111).set_xticks(arange(1,3,0.5)) # You can actually compute the interval You need - and substitute here
And so on with other aspects of Your plot. You can configure it all. Here's an example:
from numpy import arange
import matplotlib
# import matplotlib as mpl
import matplotlib.pyplot
# import matplotlib.pyplot as plt
x1 = [1,2,3]
y1 = [4,5,6]
x2 = [1,2,3]
y2 = [5,5,5]
# initialization
fig2 = matplotlib.pyplot.figure(figsize=(8.0, 5.0)) # The size of the figure is specified as (width, height) in inches
# lines:
l1 = fig2.add_subplot(111).plot(x1,y1, label=r"Text $formula$", "r-", lw=2)
l2 = fig2.add_subplot(111).plot(x2,y2, label=r"$legend2$" ,"g--", lw=3)
fig2.add_subplot(111).legend((l1,l2), loc=0)
# axes:
fig2.add_subplot(111).grid(True)
fig2.add_subplot(111).set_xticks(arange(1,3,0.5))
fig2.add_subplot(111).axis(xmin=3, xmax=6) # there're also ymin, ymax
fig2.add_subplot(111).axis([0,4,3,6]) # all!
fig2.add_subplot(111).set_xlim([0,4])
fig2.add_subplot(111).set_ylim([3,6])
# labels:
fig2.add_subplot(111).set_xlabel(r"x $2^2$", fontsize=15, color = "r")
fig2.add_subplot(111).set_ylabel(r"y $2^2$")
fig2.add_subplot(111).set_title(r"title $6^4$")
fig2.add_subplot(111).text(2, 5.5, r"an equation: $E=mc^2$", fontsize=15, color = "y")
fig2.add_subplot(111).text(3, 2, unicode('f\374r', 'latin-1'))
# saving:
fig2.savefig("fig2.png")
So - what exactly do You want to be configured?
Related Topics
Python: Getting Around Division by Zero
Jsondecodeerror: Expecting Value: Line 1 Column 1 (Char 0)
How to Get Local Issuer Certificate When Using Requests in Python
How to Prevent Brokenpipeerror When Doing a Flush in Python
Count Frequency of Words in a List and Sort by Frequency
How to Format an Integer to a Two Digit Hex
How to Check the Date Is Empty Using Python
How to Remove Unused Packages from Virtualenv
Combine Year, Month and Day in Python to Create a Date
Merge Multiple Rows to Single Row - Pandas
How to Compute Mean() for Particular Column in Pandas Dataframe Without Considering Nan Values
Changing Value in Data Frame Column in a Loop Python
Checking If a Pair of Value Is Inside a 2D Array Python
Pandas Get Frequency of Item Occurrences in a Column as Percentage
How to Split an Array According to Conditional Statement
Compare a Column Between 2 CSV Files and Write Differences Using Python