I am writing a Python package that contains a function that creates a plot of the United States. I initially wrote the code in PyCharm. Once I package the project, upload it to the TestPyPI repo, and then install it and run it in a Jupyter notebook locally I get a very different output than when I run/test it in PyCharm. The code is the same for each so I am guessing this might have something to do with how they plots are being displayed in different environments?
When I run this code in PyCharm (using plt.show() for testing):
from geostates.shapefiles import load_states
from geostates.plot import plot_states
df = load_states()
plot_states(df, column='STATEFP', extra_regions=True, labels='both', cmap='copper_r')
I get this output:
However when I run this same code in a Jupyter notebook I first import the package from TestPyPI using:
%pip install -i https://test.pypi.org/simple/ geostates==0.1.2.8
I then run the same code:
from geostates.shapefiles import load_states
from geostates.plot import plot_states
df = load_states()
plot_states(df, column='STATEFP', extra_regions=True, labels='both', cmap='copper_r');
I get this output:
As you can see, there is a significant amount of stretching that distorts the figure once it is output despite the fact that the function is using the same code. How can I fix this/why is this occurring?
The code that is originally used to construct the figure (containing all of the inset axes) is:
fig, continental_states_ax = plt.subplots(figsize=(20, 10))
# create an axis with two insets
alaska_ax = continental_states_ax.inset_axes([.08, .012, .20, .28])
hawaii_ax = continental_states_ax.inset_axes([.28, .014, .15, .19])
# create two inset plots for the extra regions
puerto_rico_ax = continental_states_ax.inset_axes([.512, .03, .11, .11])
guam_ax = continental_states_ax.inset_axes([.612, .03, .10, .15])
So this suggests that the [x, y, height, width] coordinates for the inset axis for Alaska and Hawaii is (for the y coordinate) .012 and .014 respectively. This makes sense and consequently explains the small height variation in the figure output in PyCharm. I am a little confused however why this seems to get so distorted for the Jupyter notebook output.
Any links to helpful resources such as documentation, tutorial, or examples would be greatly appreciated.
EDIT:
I am using these added magic functions in Jupyter for the rendering of my figures:
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
from Matplotlib figure displaying differently in PyCharm vs once packaged


No comments:
Post a Comment