I don't know what I have done wrong here that is making the y-tick labels clustered together. I am trying to set the label to the values in the set_yticklabels and I get the clustered in the bar chart. The x-axis ticks and labels work fine but the y-axis isn't.
What I am trying to achieve is to have the y-axis tick labels not clustered, hopefully someone can help.
Thanks
Maybe your math is wrong and your percentages go way up higher than 1. If thats true then its logical for your y-axis to appear clustered like that.
Related
I have a reasonably complicated grid of subplots that involves two sets (one on the left and another on the right) of columns plotting a set of quantities for each row, separated by a common legend to label the entries in each row.
Here is a sample of what I want to accomplish
Using matplotlib with constrained_layout = True works 95% perfectly for applying the out optimal sizes & spacing for the columns, down to the tricky case of having the legend run down the middle. The remaining 5% is highlighted in red, where the wordy x-axis tick labels seem to push away the columns: it would be perfect if there was a way to make the layout engine "ignore" the tick labels in determining the spacing.
Methods using other libraries are also appreciated. Thank you in advance.
What I tried:
subplots_adjust
GridSpec
The main difficulty with those attempts:
constrained_layout is incompatible with those settings, so one must sacrifice the optimized legend spacing at the cost of getting the column spacing right, or vice versa.
When plotting multiple plots using plt.subplots, most of the time the spacing between subplots is not ideal so the the xtick labels of the top plot would overlap with the title of the bottom plots. There is a way to fix this manually by calling say plt.subplots_adjust(hspace=0.5) and changing the parameters interactively to obtain a decent looking plot. Is there a way to calculate the subplot_adjust parameter automatically? Meaning finding the minimum hspace and wspace so that there is not overlap between texts of the plots.
You can use tight_layout https://matplotlib.org/stable/tutorials/intermediate/tight_layout_guide.html or constrained_layout https://matplotlib.org/stable/tutorials/intermediate/constrainedlayout_guide.html
I'm pretty certain that the closest your going to find to an inbuilt calculation method is:
plt.tight_layout()
or
figure.Figure.tight_layout() #if you are using the object version of the code
ax4.plot_date(x=days, y=MACD_14_21,fmt="r-",label='MACD_14_21')
I am trying to print label using label="xxx", while plotting the data, but I don't see any label printed.
Do I need to use different syntax?
These labels are for legend only. Add plt.legend() to Your code to show it. If You want to add labels on the x-axis You can do it with plt.xlabel(['label1','label2']).
Edit:
Unhappily adding labels on plotted lines, is much more complex, and I would recommend You to stick to the legend, because there is no automatic way of doing that. However if You really need to achieve that, it's explained here: Print string over plotted line (mimic contour plot labels)
For simple cases You can also use annotations.
i have plotted a figure using matshow and want to display the legend. However i only want the values between 18 and 28 to be displayed on the legend.
I have used the command :
colorbar(values=arange(18,28)).
I have exactly what i want on the colorbar in terms of color but the tick values are not displayed.
I tried with :
colorbar(ticks=arange(18,28))
and also
colorbar(ticks=arange(18,28),values=arange(18,28))
but it did not work.
How can i solve it ?
Thanks.
I am trying to change the axis labels on my plots in Chaco. I have generated with some code similar to the following:
thisplot=Plot(alldata)
thisplot.plot("xdata","ydata",value_scale="log",index_scale="log")
I would like to use the _nice_sci() formatting for the labels from the BasicFormatter class as the range is quite large (on the loglog plot) but can't work out the syntax.
Does anyone have any tips for implementing this?