1

How do you change the colors of the y-axis labels in a joyplot using joypy package?

Here is a sample code where i can change the color if the x-axis labels, but not the y-axis.

import joypy
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

## DATA
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
new_names = ['SepalLength','SepalWidth','PetalLength','PetalWidth','Name']
iris = pd.read_csv(url, names=new_names, skiprows=0, delimiter=',')

## PLOT
fig, axes = joypy.joyplot(iris)

## X AXIS
plt.tick_params(axis='x', colors='red') 

## Y AXIS     (NOT WORKING)
plt.tick_params(axis='y', colors='red') 

enter image description here

I'm pretty sure the issue is because there are mutliple sub-y-axis's, one for each density plot, and they are actually hidden already. Not sure how to access the y-axis that is actually shown (I want to change the color of "SepalLength")

Joyplot is using Matplotlib

stallingOne
  • 3,633
  • 3
  • 41
  • 63

1 Answers1

0

r-beginners' comment worked for me. If you want to change the colors of all the y-axis labels, you can iterate through them like this:

for ax in axes:
    label = ax.get_yticklabels()
    ax.set_yticklabels(label, fontdict={'color': 'r'})

This results in a warning that you're not supposed to use set_xticklabels() before fixing the tick positions using set_xticks (see documentation here) but with joypy it didn't result in any errors for me.

Here's another solution that just changes the color of the label directly:

for ax in axes:
    label = ax.get_yticklabels()
    label[0].set_color('red')
ebergeson
  • 53
  • 6