Adding in major_label_orientation value makes chart blank - python

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.)

Related

Moving bar labels to the side, so it won't overlay

I have a problem with bar labels, the values overlays with the part of the chart.
This is my code that gives the values, and I am using barplot chart
nam_atl.bar_label(nam_atl.containers[0])
Output:
Is there a way to move it a bit to the side?

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.

What's the best way to show multiple subplots of data that have the same x and y labels? (matplotlib)

I have two subplots I'd like to show horizontally. The x and y axis labels are exactly the same for both plots, even though the ticks are different. What is the most concise way I can plot them horizontally?
Plot 1:
Plot 2:
You can check Sharing axis limits and views.
Other specific examples are found here and here.
In the first link you will find an example of plots side by side. The other two examples the subplots are in a column but it is trivial to set them horizontally

How do I animate the ticks on the x-axis?

I have a matplotlib axes instance inside which I'm animating an AxesImage via blitting.
What I'd like to do is animate the ticks on the x-axis as well.
I am updating the data on the AxesImage (and subsequently) drawing its artist quite frequently, and on each update I'd like to move one extra tick placed to highlight the position of something.
This is what I'm doing right now:
axis = axes.get_xaxis
im.set_data(new_data)
axis.set_ticks([10,20,30,x,t])
axis.set_ticklabels(["p", "u", "z", "z", "i"])
axes.draw_artist(im)
axes.draw_artist(axis)
While I see the ticks correctly updating, the labels are not. I think that the axes bbox does not include the axes, is this possible? If so, how can I animate it? Should I copy and restore from somewhere else?
The axes bbox doesn't include anything outside of the "inside" of the axes (e.g. it doesn't include the tick labels, title, etc.)
One quick way around this is to just grab the entire region of the figure when you're blitting. (E.g. background = canvas.copy_from_bbox(fig.bbox))
This can cause problems if you have multiple subplots and only want to animate one of them. In that case, you can do something along the lines of background = canvas.copy_from_bbox(ax.bbox.expanded(1.1, 1.2)). You'll have to guesstimate the ratios you need, though.
If you need the exact extent of the tick labels, it's a bit trickier. The easiest way is to iterate through the ticklabel objects and get the union with ax.bbox. You can make this a one-liner: ax.bbox.union([label.get_window_extent() for label in ax.get_xticklabels()]).
At any rate, one of those three options should do what you need, I think.

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