logo
Tags down

shadow

Bar Graph in Python with 2 scales (y-axis) with matplotlib import


By : NeutralTone
Date : October 18 2020, 08:10 AM
Hope that helps So I figured out my problem and it was very simple. I'm still learning so I didn't realize that performance was for the shape of the bars on the graph, unless I'm still wrong about that. Either way, the fix was adding a second performance variable (performance2) and filling it with dimensions so that it would only create the right-most bar (percent error). This is the code and output if anybody is interested in it, or if anybody needs it.
code :
  # Create a bar graph
objects = ('Pre_Total_Profit', 'Act_Total_Profit', 'Percent_Error')
y_pos = np.arange(len(objects))
performance = [tpp, tp, pe]
performance2 = [0, 0, pe]
fig, ax1 = plt.subplots()                                 # Apply subplots to x-axis (for 2 y axis)
ax2 = ax1.twinx()                                       # Create second y-axis
ax1.set_ylabel('Dollars', color='g')        # Label y-axis in green
ax2.set_ylabel('Percent', color='m')           # Label second y-axis in magenta
ax1.set_ylim([0, (tpp+tp)])
ax2.set_ylim([0, 100])
# When graph shows, ignore the excess cyan on the left 2 bars.
ax1.bar(y_pos, performance, align='center', color='g')  # Left 2 bars (Pre/Act Profits) will show in green/centered
ax2.bar(y_pos, performance2, align='center', alpha=0.5, color='c')  # Right bar (%error) will show in cyan/centered
plt.xticks(y_pos, objects)
plt.title('Total Profits and Percent Error')

plt.show()


Share : facebook icon twitter icon

multiple axis in matplotlib with different scales


By : Bennett
Date : March 29 2020, 07:55 AM
hope this fix your issue If I understand the question, you may interested in this example in the Matplotlib gallery.
code :
from mpl_toolkits.axes_grid1 import host_subplot
import mpl_toolkits.axisartist as AA
import matplotlib.pyplot as plt

host = host_subplot(111, axes_class=AA.Axes)
plt.subplots_adjust(right=0.75)

par1 = host.twinx()
par2 = host.twinx()

offset = 60
new_fixed_axis = par2.get_grid_helper().new_fixed_axis
par2.axis["right"] = new_fixed_axis(loc="right", axes=par2,
                                        offset=(offset, 0))

par2.axis["right"].toggle(all=True)

host.set_xlim(0, 2)
host.set_ylim(0, 2)

host.set_xlabel("Distance")
host.set_ylabel("Density")
par1.set_ylabel("Temperature")
par2.set_ylabel("Velocity")

p1, = host.plot([0, 1, 2], [0, 1, 2], label="Density")
p2, = par1.plot([0, 1, 2], [0, 3, 2], label="Temperature")
p3, = par2.plot([0, 1, 2], [50, 30, 15], label="Velocity")

par1.set_ylim(0, 4)
par2.set_ylim(1, 65)

host.legend()

host.axis["left"].label.set_color(p1.get_color())
par1.axis["right"].label.set_color(p2.get_color())
par2.axis["right"].label.set_color(p3.get_color())

plt.draw()
plt.show()

#plt.savefig("Test")

Two y axis in core plot graph with different axis scales


By : WarmC
Date : March 29 2020, 07:55 AM
I wish this help you If you want the two y-axes to have different scales, you need to add another plot space. Use the same xRange for the second plot space, but use a different yRange, e.g.,
code :
CPTXYPlotSpace *plotSpace2 = [[[CPTXYPlotSpace alloc] init] autorelease];
plotSpace2.xRange = plotSpace.xRange;
plotSpace2.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(ymin)
                                                 length:CPTDecimalFromFloat(ymax2 - ymin)];
[graph addPlotSpace:plotSpace2];
y2.plotSpace = plotSpace2;
y.majorIntervalLength = CPTDecimalFromFloat((ymax - ymin) / 10.0f);
y2.majorIntervalLength = CPTDecimalFromFloat((ymax2 - ymin) / 10.0f);

How to equalize the scales of x-axis and y-axis in Python matplotlib?


By : Milan Gunasekera
Date : March 29 2020, 07:55 AM
will help you I wish to draw lines on a square graph. , You need to dig a bit deeper into the api to do this:
code :
from matplotlib import pyplot as plt
plt.plot(range(5))
plt.xlim(-3, 3)
plt.ylim(-3, 3)
plt.gca().set_aspect('equal', adjustable='box')
plt.draw()

Matplotlib similar axis scales


By : Pranav Koli
Date : March 29 2020, 07:55 AM
around this issue How can I command matplotlib to plot my x- and y-axis to the same scale, i.e. that a unit length on both axes correspond to to the same physical distance on my screen or ons a piece of paper? , You can use set_aspect() method of Axes:
code :
import pylab as pl
pl.gca().set_aspect("equal")

how to have two y scales in matplotlib while having a date on x axis


By : Nikov
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Not every datapoint in your plot has its own ticklabel. Here you have 13 ticklabels, but 366 datapoints, hence the error.
If you have a dataframe df with three columns x,y,z, you can plot it two twin axes via
code :
ax=df[['x','y']].set_index('x').plot()
ax2 = ax.twinx()
df[['x','z']].set_index('x').plot(ax=ax2)
Related Posts Related Posts :
  • Get mongod rs.status() results from a python script
  • ImportError: C extension: No module named 'parsing' not built
  • python pandas update column values related to previous updated row during iteration over it
  • 3 nested loops: Optimizing a simple simulation for speed
  • Assign subset of values to pandas dataframe with MultiIndex
  • How to group two sets of buttons on each top corner of the screen using Tkinter?
  • django login using class based for custom user
  • MRJob sort reducer output
  • Python Pandas Counts using rolling time window
  • Getting or editing a string from a column in a csv file with pandas
  • Python - Delete row in matrix/array if row contains
  • Using dicom Images with OpenCV in Python
  • Odoo ghost record
  • Creating and assigning multiple variables in a tkinter application
  • Graph dictionary
  • No changes to original dataframe after applying loop
  • AUC of Random forest model is lower after tuning parameters using hypergrid search and CV with 10 folds
  • Python: Reading multiple CSV files, and assigning each to a different variable
  • How to identify empty rectangle using OpenCV
  • How to iterate multilevel dataframe in python
  • How to limit the contour plot with a line plot?
  • Why subclassing a str or int behaves differently from subclising a list or dict?
  • Python decode with translation table
  • i need to click unordered links in the below URL using selenium, python
  • How to join pandas dataframe with itself?
  • How to apply a color cast to a video frame in OpenCV Python?
  • Is there any existing library for median filtering with kernel size greater then 5 using OpenCL acceleration in python?
  • Changing the color of points in scatter plot for different dummy values
  • Calculate center for each polygon in a list efficiently
  • Loading modules in the same Python package
  • replacing pixels in an imagewith pixels from another image python
  • Suggestion on picking the best options of two lists (minimum and maximum )python
  • Resetting Index in a Dataframe drops the Indexed column by 1 row
  • Convert number which are str from readlines to digits - python
  • Unable to authenitcate with python minds api
  • Print variables from a query in python
  • Ipython does not see the installed library
  • Javascript-like array-method chaining in Python?
  • PyQT: Get contents CustFormWidgetIem inside QListWidgetItem
  • Bottle server: HTTPResponse vs bottle.response
  • pytorch vgg model test on one image
  • Runtime scope and `main` symbol is different inside or outside a function
  • Use anaconda in pycharm (Import libraries error, updating anaconda and virtual environment)
  • how to get the sum of a CSV column list to print
  • Python plot drop lines with repeating value in column
  • receive binary file from POST request with BaseHTTPRequestHandler
  • D-Bus - 'ServiceUnknown' exception encountered while calling a remote procedure
  • Pandas .min() method doesn't seem fastest
  • Pandas: How to reference columns of structure: ('Name', n) ('Name', n+1)
  • Read a text file and remove all characters except alphabets & spaces in Python
  • Compute all powerset intersections of two lists
  • Applying literal_eval on string of lists of POS tags gives ValueError
  • Modelling a logic puzzle
  • What is the meaning of Copy_X in sklearn linear models
  • selenium.common.exceptions.ElementNotInteractableException: Message: Element is not displayed
  • pydev debugger does not stop in breakpoint
  • Python windows path regex
  • Flask and selenium-hub are not communicating when dockerised
  • How to use groupby on a single column and perform comparisons for multiple columns in Pandas?
  • Locate a python script without absolute path
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org