FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[Bug]: Changing color using ax.tick_params · Issue #24227 · matplotlib/matplotlib · GitHub

Repository navigation

[Bug]: Changing color using ax.tick_params #24227

Closed

Description

Bug summary

When trying to change the color of the x and y axis I am using ax.tick_param.
If I use label color 'r' or labelcolor='#00000077', but if I write label color='grey' or a hex value: #bdbdbd then the background changes too. Is that expected?

This works:

ax.tick_params(labelsize=22,  labelcolor='#00000077', top = False,  left=False)

This doesnt:

ax.tick_params(labelsize=22,  labelcolor='#BDBDBD', top = False,  left=False)

Code for reproduction

url='https://raw.githubusercontent.com/Curbal-Data-Labs/Matplotlib-Labs/master/2018w48.csv'
dataset = pd.read_csv(url)

dataset.drop_duplicates(['city','item'], inplace=True)
dataset.pivot_table(index='city', columns='item', values='cost', aggfunc='sum', margins = True).sort_values('All', ascending=True).drop('All', axis=1)

df = dataset.pivot_table(index='city', columns='item', values='cost', aggfunc='sum', margins = True).sort_values('All', ascending=True).drop('All', axis=1).sort_values('All', ascending=False, axis=1).drop('All').reset_index()

# comma replace
for c in df.columns[1:]:
    df[c] = df[c].str.replace(',','.').astype(float)

fig, axes = plt.subplots(nrows=1, ncols=5, figsize=(30,10), sharey=True)

colors = ['green','blue','red','black','brown'] 
col_names = ['Dinner','Drinks at Dinner','2 Longdrinks','Club entry','Cinema entry']

for i, (ax,col,c) in enumerate(zip(axes.ravel(), col_names, colors)):
    ax.plot(df.loc[:,col], df['city'], marker='o', markersize=25, lw=0, color=c)
    ax.set_title(col)
    for i,j in zip(df[col], df['city']):
        ax.annotate('$'+str(i), xy=(i, j), xytext=(i-4,j), color="white", fontsize=8)
    ax.set_xticks([])
    ax.spines[['top', 'right', 'left', 'bottom']].set_visible(False)
    ax.grid(True, axis='y', linestyle='solid', linewidth=2)
    ax.grid(True, axis='x', linestyle='solid', linewidth=0.2)
    ax.xaxis.tick_top() 
    ax.xaxis.set_label_position('top')
    ax.set_xlim(xmin=0, xmax=160)
    ax.xaxis.set_major_formatter('${x:1.0f}')
    ax.tick_params(labelsize=8, labelcolor = #bdbdbd, top=False, left=False)

plt.show()

Actual outcome

Expected outcome

Additional information

No response

Operating system

Win11

Matplotlib Version

3.5.1

Matplotlib Backend

No response

Python version

3.10

Jupyter version

3.3.2

Installation

conda

Activity

  1. suuuehgi commented on Oct 20, 2022

    This exact code gives me

    using 'grey' although I think to recall seeing that once as well within Jupyter Lab ... but I think it was just related to the inline display, not the actual output of .savefig().

  2. ruthpozuelo commented on Oct 20, 2022

    Author

    I am using Jupyter Lab and I am indeed looking at the inline display. Got it!

  3. timhoffm commented on Oct 20, 2022

    Member

    I'm sorry, I cannot follow your description.

    A wild guess is that you use labelcolor='#77', which is not a valid color name. This is only checked at draw time and can result in drawing some parts of the figure and then raising an exception.

    If that's not it, please clean up your original description

    • Use inline code formatting (i.e. backticks) to mark code fragments, .e.g. labelcolor='grey'.
    • Be precise on what you write, sometimes you write "label color", sometimes you write "labelcolor".
    • This works / this does not work contains exactly the same code
    • The code for reproduction misses qoutes on the labelcolor value and is thus not executable.
  4. ruthpozuelo commented on Oct 20, 2022

    Author

    Hi @timhoffm ,
    It is github that trims the text, it says # 00 00 00 00 77 in reality, same with labelcolor= 'r'.
    I think the issue is what @suuuehgi describes, I am using jupiter labs and the issue shows only on the inline display. When I moved the code to power bi it worked.

  5. QuLogic commented on Oct 21, 2022

    Member

    When writing code in Markdown, you should surround it with backticks. I have inserted some where I think they should go, but I am not 100% certain, so please edit again and correct any that are wrong.

  6. ruthpozuelo commented on Oct 21, 2022

    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL