question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Description

I’m running into an error after upgrading the proplot version . The error occurs when using contourf, the error message is KeyError: ‘red’

Steps to reproduce

# your code here
# we should be able to copy-paste this into python and exactly reproduce your bug

import proplot as plot
import matplotlib.pyplot as plt
import numpy as np

f, axs = plot.subplots(ncols=1, nrows=1) 

#generate random data
data=np.ones((180,360))
data[20:80,80:150]+=1

x=np.arange(0,360,1)
y=np.arange(0,180,1)

axs.contourf(x,y,data,cmap=plt.cm.coolwarm)

plt.show()

Expected behavior: A simple contourf plot

Actual behavior: An error message occured and the plot was not produced

Equivalent steps in matplotlib

Pretty sure its Proplot. With matplotlib this works

import matplotlib.pyplot as plt
import numpy as np

f,axs=plt.subplots()

#generate random data
data=np.ones((180,360))
data[20:80,80:150]+=1
x=np.arange(0,360,1)
y=np.arange(0,180,1)

axs.contourf(x,y,data,cmap=plt.cm.coolwarm)
plt.show()

Proplot version

Matplotlib: 3.4.1 Proplot: 0.9.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
lukelbdcommented, Sep 17, 2021

No problem. Thanks for your clarification – after that I found the solution relatively quickly (182a186).

The Colormap constructor function converts input native matplotlib colormaps to proplot’s colormap subclasses (i.e. ListedColormap to DiscreteColormap, LinearSegmentedColormap to ContinuousColormap). There was a bug in the conversion process that caused erasure of the original segmentdata. This happened the first time the native matplotlib colormap was passed through Colormap (i.e., the first hist2d call). To fix this, I simply make sure to copy the native colormap segment data dictionary before using it for the new colormap.

0reactions
ghostcommented, Sep 20, 2021

Thanks @matthias-k for digging further and @lukelbd for addressing the issue so quickly!

Read more comments on GitHub >

github_iconTop Results From Across the Web

matplotlib.pyplot.contourf — Matplotlib 3.6.2 documentation
It is an error to use vmin/vmax when a norm instance is given (but using a str norm name together with vmin/vmax is...
Read more >
Filled 2-D contour plot - MATLAB contourf - MathWorks
This MATLAB function creates a filled contour plot containing the isolines of matrix Z, where Z contains height values on the x-y plane....
Read more >
some contourf levels not drawn in Orthographic projection (are ...
I think this is a very serious bug. This makes it impossible to reliably produce filled contours when looking at the poles. Is...
Read more >
GNU Octave - Bugs: bug #62874, text in contourf is not well ...
Plotting a contourf and adding text on isolinee withe clable results in unreadable/ bad readable values. Anonymous. (-)Attached Files(+)Attached ...
Read more >
pyplot.contourf() returns error when specified levels argument
0. I'm trying to make a contour plot in Python using the matplotlib.pyplot.contourf() function, and it works perfectly like this ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found