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.

Plotly Ignores Colors

See original GitHub issue
  • Weights and Biases version: ‘0.8.21’
  • Python version: 3.5.3
  • Operating System: GCP AI Notebook with Tensorflow 2.0 Environment Jupyter Lab

Description

If I create a bar plot using matplotlib.pyplot and pass in a set of colors to use for each bar, it displays the plot correctly with the corresponding colors. When I log this plot to wandb, the plot displayed in wandb shows the correct bars but all the same color. Alternatively, if I log the plot to wandb as an image, it uploads the plot correctly with the corresponding colors.

What I Did

import numpy as np
import matplotlib.pylplot as plt
import seaborn as sns

lengths, modes = np.unique(counts, return_counts=True)
pal = list(sns.color_palette("hls", len(lengths)))
plt.bar(lengths[1:], modes[1:], color=pal)
plt.xlabel('Visit Lengths')
plt.ylabel('Frequency')
wandb.log({'Visit Length Distribution' : plt})

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
vanpeltcommented, Jan 23, 2020

I have a branch that fixes this, you can use with: pip install --upgrade git+git://github.com/wandb/client.git@bug/plotly_np#egg=wandb we’ll get this out in the next release.

0reactions
lorinczszabolcscommented, Sep 4, 2021

Hi! I was facing a similar issue, when I created a seaborn scatter plot. When logging as a wandb.Image, it showed the colors, but when I logged the figure directly, the colors were not shown on the legend, only on the actual points in the scatter plot.

Example:

from matplotlib import pyplot as plt
import seaborn as sns

def _get_color_mapping():
    return {
        'tree': '#124A54', 'sky': '#28A2B8', 'bear': '#58C9DA',
        'bee': '#ADE68E', 'honey': '#CBFCB1'}

classes = np.array(['tree', 'sky', 'bear', 'bee', 'honey'])
fig, _ = plt.subplots(figsize=(10., 10.))
sns.scatterplot(x=np.random.random(1000), y=np.random.random(1000), hue=classes[np.random.randint(0, 5, (1000))], palette=_get_color_mapping())

wandb.log({
        "Figures/scatter": wandb.Image(fig) # works
        # "Figures/scatter": fig # colors do not appear in legend
        })

For info:

plotly==5.3.1 matplotlib==3.3.4 seaborn==0.11.2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plotly ignores my custom colors in a 3d Scatter plot
If you don't use it, Plotly tries to use the colours specified in the color array as colors to be assigned to categories...
Read more >
colors argument to add_trace is ignored #1699 - GitHub
The colors argument is ignored. The same happens when specifying a custom colour palette with colorRampPalette from RColorBrewer : library( ...
Read more >
Ggplotly ignoring ggplot geom_point fill colors - Plotly R
fig results in a plot that have different point fill colors depended on the max rain, but fig 2 turns every point fill...
Read more >
Colors mode doesn't work with a second added trace - Plotly R
With this method the plot is correctly done but the colors shown are not the ones choosen in “color_a” and “color_b”. they are...
Read more >
JavaScript Figure Reference: Single-Page - Plotly
Has an effect only if in `marker.color` is set to a numerical array. ... If `false`, this stop is ignored even within its...
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