Does changing the y-axis and x-axis label changes anything in the image using imshow? - matplotlib

I want to show values as pixels. But my x-axis and y-axis show different range.I don't know what these values are telling us. But I read somewhere that we have to read the values as intensity values. They will not be visualized on the axis. Then what these axis are telling us? Secondly if I use xticks and yticks to label x and y axis does it has any effect on the image? Does it flip anything in the image?
`# a is an array of shape(500,2)
plt.xticks(np.arange(0,2))
plt.yticks(np.arange(0,500))
plt.imshow(a,aspect='auto',cmap=plt.cm.gray)`

Related

How to move y axis label further from side of “paper”

I have a data set “mydatainR”
With that I created a barplot and when I download the barplot, part of the y axis is cut off because it’s “off of the paper”
I want to give myself more room to work with, or make my entire bar plot smaller. Thx

Matplotlib: How to place x-axis and y-axis TITLES at edges of frame, even if origin is not at bottom left?

I'm making plots where the (0,0) position is not necessarily in the bottom left corner of the plot frame, meaning that the x and y axes and their ticks cross within the plot frame. It's fine to have the lines, ticks and their values within the frame, but having the axis titles so near to their lines interferes with visualization of certain data points.
I'd simply like to force the x and y axis titles to be at the bottom and far left of the plot frame, respectively; it doesn't work to simply 'pad' the xlabel or ylabel titles because the padding I'd need would vary between plots.
How to get the titles always in these consistent locations of the plot frame, even if the corresponding axis lines, ticks/values may vary in the plot frame space?
Thank you.
I'd like to add a note here. It seemed to me that it could be possible to define the xlabel and ylabel 'labelpad' values directly from the data range:
For example, one could find the minimum x-value of the minimum y-value (this would set the position of the x-axis label), and the minimum x-value of the minimum x-value (this would set the position of the y-axis label):
xpad = ax.get_ylim()[0]
ypad = ax.get_xlim()[0]
Then use these values in xlabel and ylabel parameters as labelpads:
pylab.xlabel("X Title", fontsize=12, labelpad=abs(xpad))
pylab.ylabel("Y Title", fontsize=12, labelpad=abs(ypad))
Unfortunately, it doesn't look like labelpad can accept variables. Any suggestions that might allow a work-around?

dual y axis plotting causes data points looks messy at left corner of chart

i am using MPAndroid charting toolkit for data visualization. chart plotting smooth in MPAndroid but problem arise when i try plot dual y axis(left& right). As right axis appear data points on spread over the x axis completely. all data points appearing on the left of chart. How can i spread the data points ?
mChart = (LineChart) findViewById(R.id.Chart);
mChart.setGridBackgroundColor(Color.parseColor("#F4F4F4"));
mChart.setDrawGridBackground(false);
mChart.setTouchEnabled(true);
mChart.setHighlightEnabled(false);
mChart.setDragEnabled(false);
mChart.setScaleEnabled(true);
mChart.setPinchZoom(true);
mChart.setDescription("");
mChart.getAxisLeft().setAxisMaxValue(YMaxValue);
mChart.getAxisLeft().setAxisMinValue(YMinValue);
mChart.getAxisLeft().setStartAtZero(false);
mChart.getAxisRight().setEnabled(false);
if(General.InnerClass.Y2AxisValues.size()>0)
{
mChart.getAxisRight().setEnabled(true);
mChart.getAxisRight().setSpaceBottom(12.25f);
mChart.getAxisRight().setAxisMaxValue(Y2MaxValue);
mChart.getAxisRight().setAxisMinValue(Y2MinValue);
mChart.getAxisRight().setStartAtZero(false);
mChart.getXAxis().setAvoidFirstLastClipping(true);
}
mChart.setData(data);
progbar.setVisibility(View.GONE);
mChart.invalidate();
Before
After
The data points are exactly where they should be. The only thing that has changed is the range of values that is displayed on each axis.
--> this range is now significationly lower because only one set of data is represented by each axis, before, one axis had to scale large enough to display both datasets.
I suggest you read the documentation of the YAxis and simply increase the range of values that should be displayed on the axis.
while plotting y2 axis providing the x values is the problem. values for the x axis should be provide for single time. providing twice add the values to x axis exiting values get doubled.
thnx #philipp

Matplotlib tick labels

Is there a way to render the tick labels just right inside the axes, i.e, something like the direction property there is on the ticks themself?
Right now I'm setting the x property to a positive value on the ticklabels to draw them inside of the axis, i.e.,
ax2.set_yticklabels(['0', '2500', '5000', '7500'], minor=False, x=0.05)
But this doesn't really work on resizable plots, as the 0.05 figure is absolute (and too big on big plots).
Any ideas?
I'm assuming that ax2 is constructed as ax2 = ax.twinx(), which is to say that it is on the right side of the axes.
You could do something like the following:
ax2.set_yticklabels(['0', '2500', '5000', '7500'], minor=False, horizontalalignment='right')
for tick in ax2.yaxis.get_major_ticks():
tick.set_pad(-8)
If you want the left side axis on the inside too, then you'd simply switch the horizontal alignment to 'left' and change the pad from -8 to -25.
The two numbers might not be exact and could depend on other matplotlib settings you might have (e.g. length of major ticks) so you may want to increase or decrease those values slightly.

Setting Axis Label offset in core plot

After setting the bar offset , the axis labels are not displaying at the center of the bar and getting misplaced. Can any one help me with this ??
The barOffset moves the centers of the bars away from the bar locations provided by the datasource. If the axis labels are at the bar locations, they won't line up with the bars.
Possible solutions:
Set the barOffset to zero (0).
Change the axis labeling policy to place the labels under the bars. This will also move any tick marks on the axis unless you make custom labels.