How to troubleshoot seaborn legend_out not working correctly with catplot or relplot? - seaborn

With seaborn 0.11.1 and matplotlib 3.3.4 this...
import matplotlib as mpl
from matplotlib import pyplot as plt
print(sns.__version__, mpl.__version__)
import seaborn as sns
sns.set_theme(style="ticks")
exercise = sns.load_dataset("exercise")
g = sns.catplot(x="time", y="pulse", hue="kind", data=exercise)
plt.show()
...the result is supposed to look like this:
However, when I do that in JupyterLab or Plotly-Dash I get:
I deleted ~/.config/matplotlib and setup a clean conda environment with minimal packages. Same result.

plt.rcParams['figure.autolayout'] = False
fixes it.

Related

Get and install requirements.txt for python file into virtualenv

I have the following packages I need to install into my virtual environment for an app deployment. This is how they read at the top of my app's file:
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime, timedelta, date
from dateutil.relativedelta import relativedelta
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from scipy import stats
from sklearn import metrics
import plotly.express as px
import plotly.graph_objects as go
import plotly.figure_factory as ff
import statsmodels.api as sm
I'm not sure how to install the ones that say "from x import y, z". I'd also much prefer to do something more global(?) than install each thing one by one into the virtualenv.
As I understand it, the pip freeze > requirements.txt command only generates a requirements file based on what's manually been installed into the virtualenv. I'd rather get something together that looks at my app file and generates a requirements.txt based on that, and then install the contents of the requirements.txt into the virtualenv directly, as opposed to installing each package one by one.
from foo import bar is essentially equivalent to:
import foo
bar = foo.bar
It just imports the module then loads some of its variables into scope. So, from scipy import stats would be in the scipy module. As for automatically generating a requirements.txt, this is what pipreqs is made for.
I installed pipreqs and then used
pipreqs .
from command line while in the directory of the folder with the app in it. This generated a requirements.txt with all the proper packages. Still working on installing the requirements.txt into the virtualenv, but thats been answered many times elsewhere.
EDIT: install requirements.txt into virtualenv using:
pip install -r requirements.txt

Is there an equivalent for using matplotlib.image in ruby

Been experimenting with using Ruby inside a jupyter notebook. With Python I can do this
import matplotlib.image as mpimg
Does anyone know the equivalent with Ruby, I have not been able to find it in any of the iRuby or sciruby documentation?
To clarify a little, In my gemfile I have this
gem 'iruby'
gem 'cztop'
gem 'matplotlib'
But cannot seem to get access to the image part of matplotlib that I am use to using in python.
I am trying to find the Ruby version of what, in Python, I would write like this
#importing some useful packages
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
...
%matplotlib inline
#reading in an image
image = mpimg.imread('test_images/solidWhiteRight.jpg')
#printing out some stats and plotting
print('This image is:', type(image), 'with dimesions:', image.shape)
plt.imshow(image) #call as plt.imshow(gray, cmap='gray') to show a grayscaled image
Thanks so much for any suggestions
This is how far I can get it to work in jupyter notebook on MacOSX:
require 'matplotlib/pyplot'
plt = Matplotlib::Pyplot
image = plt.imread 'test.png'
puts "This image's dimensions: #{image.shape}"
plt.imshow(image)
plt.show()
I used your Gemfile with the additional gem rbczmq to avoid the kernel dying (hint found here):
gem 'iruby'
gem 'cztop'
gem 'matplotlib'
gem 'rbczmq'
Note that I used a .png because matplotlib can only read PNGs natively without PIL installed.
This is how the result will look like:
Displaying the result inline as in the python version:
seems to be impossible.

Tensorflow .so issues Mac OS X

I am having trouble getting the Tensorflow example to progress beyond the first line of code beyond my imports. With no other errors, I receive the following:
NotFoundError: dlopen(/Users/opusandcaymus/Election/word2vec_ops.so, 6): image not found
I have a dedicated Tensorflow environment in Anaconda 4.0.1 running Python 3.5. Tensorflow was freshly installed in that environment as version 1.4.1. I'm not sure what the .os file does for word2vec, but Google's example problem requires this line (Google Example Link). Thanks in advance.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import sys
import threading
import time
from six.moves import xrange # pylint: disable=redefined-builtin
import numpy as np
import tensorflow as tf
word2vec = tf.load_op_library(os.path.join(os.path.dirname(os.path.realpath("__file__")), 'word2vec_ops.so'))

ipython notebook not finding mathplotlib module

This is what I see when I try to import mathplotlib
In [11]:
import numpy as np
import mathplotlib.pyplot as plt
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-11-d33586aa69ae> in <module>()
1 import numpy as np
----> 2 import mathplotlib as plt
ImportError: No module named mathplotlib
I am not sure it is relevant but in other forums people talk about their .bashrc files.
Lindas-iMac:~ iMacLinda$ cat .bashrc
export PATH="/Users/iMacLinda/anaconda/bin:$PATH"
Matplotlib is definitely installed
Lindas-iMac:~ iMacLinda$ conda list | grep matplo
matplotlib 1.4.3 np110py27_3
I have done the following updates
conda update ipython 
conda update ipython-notebook 
conda updata ipython-qtconsole 
Does anyone have a solution to this?
sorry the problem was a typo. It should be matplotlib and not mathplotlib

Pandas .plot() call freezing GUI

I'm attempting to create graphs using pandas on Python 2.7 OSX 10.
import numpy as np
import pandas as pd
import Quandl
pd.options.display.mpl_style = 'default'
TOKEN = 'tWquoUMLCebqSBMbTFNg'
print 'Pandas Version', pd.__version__
print 'Numpy version', np.__version__
uk_df = Quandl.get('OECD/HEALTH_STAT_CICDHOCD_TXCMILTX_GBR', authtoken=TOKEN)
print uk_df.head(8)
uk_df.plot()
Output:
Pandas Version 0.12.0
Numpy version 1.8.0
…and then some data. The Python GUI spaceship attempts to open, but bounces forever. What am I missing here?
I have the latest matplotlib installed as well.

Resources