Home > Blockchain >  Show dates in xticks only where value exist in plot chart of multiple dataframes
Show dates in xticks only where value exist in plot chart of multiple dataframes

Time:01-08

I have got a matplotlib question about xticks. I wanted to hide all those values that do not occur. I actually did it, but for the second set of values (red chart). I found how to hide for a specific data frame but not for 2 or more.

This is my code:

plt.subplots(figsize=(2, 1), dpi=400)
width = 0.005

xlim = np.arange(0, 1, 0.01)
ylim = np.arange(0, 0.1, 0.001)


plt.xticks(density_2.index.unique(), rotation=90, fontsize=1.5)
plt.yticks(density_2.unique(), fontsize=2)
plt.bar(density_1.index, density_1, width, color='Green', label=condition_1,alpha=0.5)
plt.bar(density_2.index, density_2, width, color='Red', label=condition_2,alpha=0.5)
plt.legend(loc="upper right", fontsize=2)
plt.show()

Link where I saw the solution: enter image description here

CodePudding user response:

You need to find the intersection of the two lists of density_1's and density_2's ticks, as enter image description here

Zoom in:

enter image description here

  •  Tags:  
  • Related