Comments (5)
Thanks for the examples (and your interest)! Never thought of using seaborn with ProPlot. This is probably related to my fill_between_wrapper
overrides. All of ProPlot's plotting wrappers are supposed to be strict supersets/not interfer with usage of the existing matplotlib API, but I appear to have overlooked something. Will get to it within the next few days.
from proplot.
from proplot.
Sorry for the delay -- the latest commit (c45c88a) fixes this. The source of the bug is complicated, but basically I was wrapping the matplotlib.axes.Axes.hist
method improperly. Try running pip uninstall proplot
then re-installing with pip install git+https://github.com/lukelbd/proplot.git#egg=proplot
(when ProPlot is officially released it will use a versioning system, but for now I'm just pushing bugfixes directly to master).
Also note that you cannot specify both the figure dimensions and the axes dimensions. If you input the former the latter will be ignored. ProPlot now issues a warning when this happens.
from proplot.
And thanks again for posting the example, you made it a very quick fix.
from proplot.
@tommylees112 maybe you can help me with this. When I try and run your code above I get ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
. Did you ever run into this error?
I just installed proplot so I have version 0.5.0.
Here's the code I used:
import pandas as pd
import xarray as xr
import numpy as np
import seaborn as sns
import proplot as plot
import calendar
def drop_nans_and_flatten(dataArray: xr.DataArray) -> np.ndarray:
"""flatten the array and drop nans from that array. Useful for plotting histograms.
Arguments:
---------
: dataArray (xr.DataArray)
the DataArray of your value you want to flatten
"""
# drop NaNs and flatten
return dataArray.values[~np.isnan(dataArray.values)]
# create dimensions of xarray object
times = pd.date_range(start='1981-01-31', end='2019-04-30', freq='M')
lat = np.linspace(0, 1, 224)
lon = np.linspace(0, 1, 176)
rand_arr = np.random.randn(len(times), len(lat), len(lon))
# create xr.Dataset
coords = {'time': times, 'lat':lat, 'lon':lon}
dims = ['time', 'lat', 'lon']
ds = xr.Dataset({'precip': (dims, rand_arr)}, coords=coords)
ds['month'], ds['year'] = ds['time.month'], ds['time.year']
f, axs = plot.subplots(nrows=4, ncols=3, axwidth=1.5, figsize=(8,12), share=2) # share=3, span=1,
axs.format(
xlabel='Precip', ylabel='Density', suptitle='Distribution',
)
month_abbrs = list(calendar.month_abbr)
mean_ds = ds.groupby('time.month').mean(dim='time')
flattened = []
for mth in np.arange(1, 13):
ax = axs[mth - 1]
ax.set_title(month_abbrs[mth])
print(f"Plotting {month_abbrs[mth]}")
flat = drop_nans_and_flatten(mean_ds.sel(month=mth).precip)
flattened.append(flat)
sns.distplot(flat, ax=ax, **{'kde': False})
And the error:
Plotting Jan
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-1-bea6a445aa3a> in <module>
46 flat = drop_nans_and_flatten(mean_ds.sel(month=mth).precip)
47 flattened.append(flat)
---> 48 sns.distplot(flat, ax=ax, **{'kde': False})
49
~/miniconda3/envs/maize-Toff/lib/python3.7/site-packages/seaborn/distributions.py in distplot(a, bins, hist, kde, rug, fit, hist_kws, kde_kws, rug_kws, fit_kws, color, vertical, norm_hist, axlabel, label, ax)
226 ax.hist(a, bins, orientation=orientation,
227 color=hist_color, **hist_kws)
--> 228 if hist_color != color:
229 hist_kws["color"] = hist_color
230
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Bringing this up because I'm trying to make a similar plot (proplot subplots + sns.distplot()) but am running into that ValueError for my code as well. Hoping it's an easy fix.
from proplot.
Related Issues (20)
- Bug: xticklabels overwrites xminorticks setting HOT 3
- Cannot pass norm argument to hist2d
- Any timeline for a relase that supports matplotlib >=3.5?
- Proplot changes names of colormaps to lowercase, breaking `matplotlib.pyplot.get_cmap`
- MatplotlibDeprecationWarning with unexpected argument for savefig() HOT 3
- proplot can't plot string like datetime
- Inset_axes zooms doesn't show lines
- Trying to make a line over contourf returns TypeError HOT 5
- TypeError: tricontourf() takes 4 positional arguments but 5 were given
- Option for adding errorbar legend
- Nonsticky bounds
- How to use proplot in MATLAB HOT 1
- path effects not pretty
- May I ask how to import. shp format files into proplot HOT 1
- Set markercolor for scatter plots with a substring from another columns using .map() and colordict HOT 1
- Change the 'N' notation by decimal lat/lon degrees HOT 2
- Support matplotlib >= 3.6.0 HOT 3
- Migrate proplot repo to be housed under another open-source development group? HOT 5
- how to install? HOT 2
- Issue importing proplot HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proplot.