Colorbar tick values not displayed python - python

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.

Related

Adding in major_label_orientation value makes chart blank

I'm creating a bar chart using Bokeh. My chart renders fine initially, but when I add in the following line (to rotate the X labels):
p.xaxis.major_label_orientation = 1.2
The chart becomes blank. Why is this occurring?
It turns out that this occurred because my x axis labels were too long. When I shortened the labels, the chart reappeared with the rotated labels. (Increasing the height of the figure might be another way to solve this issue.)

Y-axis label clustered Matplotlib

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.

Having a colorbar for a bar plot in python

Hi I don't know if this is possible, but I have made a bar plot in python where the color is a hex value. If I have the value that a hex code corresponds to, is it possible to make a colorbar for my bar plot in python? Or is there a way to use a colormap for bar plots in python?
This is my image right now. The color corresponds to a value, and I want to add a colorbar that has a range of colors with the value it will be. I have done this for scatter plots but I did not use a color map but just hex values for each bar.
Matplotlib does support colobars. Here's the API:
http://matplotlib.org/api/colorbar_api.html
Here's a code sample of a colorbar associated with a plot:
http://matplotlib.org/examples/pylab_examples/colorbar_tick_labelling_demo.html
EDIT:
Specifically to a bar plot, you could use a LinearSegmentedColormap instead of a colorbar, as in here

matplotlib: enlarge axis-scale label

Is there a way to enlarge the axis-scale label in matplotlib (circled in red in the enlarged plot below)?
I've used ax.tick_params() to successfully edit the tick labels, but I haven't been able to find anything about this specific piece of the plot.
Worse comes to worst, I could go with a manual text() insertion, but I'd like something more direct if possible.
Add a line like this
ax.xaxis.get_children()[1].set_size(15)
To change your major tick scale label (I guess we can call it so) to 15 points, if you plot the plot on ax.
If you plot using the pyplot API, add a line of ax=plt.gca() as well.

Drawing a chart with proportional X axis in Python

Is there an easy way to draw a date/value chart in Python, if the "dates" axis had non-equidistant values?
For example, given these:
2009-02-01: 10
2009-02-02: 13
2009-02-07: 25
2009-03-01: 80
I'd like the chart to show that between the 2nd and 3nd value there's a longer gap than between the 1st and the 2nd.
I tried a few chart libraries but they all seem to assume that the X axis has non-scalar values..
(Side note: the chart should be exportable to PNG/GIF/whatever)
Thanks for your time!
you should be able to do this with matplotlib barchart. you can use xticks to give the x-axis date values, and the 'left' sizes don't have to be homogeneous. see the documentation for barchart for a full list of parameters.
If it is enough for you to get a PNG with the chart, you can use Google Chart API which will give you a PNG image you can save. You could also use your data to parse the URL using Python.
EDIT: Image URL for your example (very basic).

Categories